clerk/internal/lsp/server.go (view raw)
Oleksandr Smirnov
Oleksandr Smirnov
olexsmir@gmail.com lsp: init server, report diagnostics, 19 days ago
olexsmir@gmail.com lsp: init server, report diagnostics, 19 days ago
| 1 | package lsp |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "log/slog" |
| 6 | "sync" |
| 7 | "time" |
| 8 | |
| 9 | "go.lsp.dev/protocol" |
| 10 | "go.lsp.dev/uri" |
| 11 | |
| 12 | "olexsmir.xyz/clerk/internal/linter" |
| 13 | "olexsmir.xyz/clerk/journal" |
| 14 | "olexsmir.xyz/clerk/journal/semantic" |
| 15 | ) |
| 16 | |
| 17 | type server struct { |
| 18 | protocol.UnimplementedServer |
| 19 | |
| 20 | client protocol.Client |
| 21 | log *slog.Logger |
| 22 | |
| 23 | version, name string |
| 24 | |
| 25 | linter *linter.Linter |
| 26 | loader *journal.Loader |
| 27 | debouncer *time.Timer |
| 28 | |
| 29 | mu sync.Mutex |
| 30 | openDocs map[uri.URI]docState |
| 31 | semanticCtx *semantic.Context |
| 32 | } |
| 33 | |
| 34 | type docState struct { |
| 35 | text string |
| 36 | version int32 |
| 37 | languageID protocol.LanguageKind |
| 38 | } |
| 39 | |
| 40 | func (s *server) Initialize(ctx context.Context, params *protocol.InitializeParams) (*protocol.InitializeResult, error) { |
| 41 | return &protocol.InitializeResult{ |
| 42 | ServerInfo: protocol.ServerInfo{ |
| 43 | Name: s.name, |
| 44 | Version: protocol.NewOptional(s.version), |
| 45 | }, |
| 46 | Capabilities: protocol.ServerCapabilities{ |
| 47 | DocumentFormattingProvider: &protocol.DocumentFormattingOptions{}, |
| 48 | TextDocumentSync: &protocol.TextDocumentSyncOptions{ |
| 49 | OpenClose: new(true), |
| 50 | Change: new(protocol.TextDocumentSyncKindFull), |
| 51 | }, |
| 52 | }, |
| 53 | }, nil |
| 54 | } |
| 55 | |
| 56 | func (s *server) Initialized(ctx context.Context, params *protocol.InitializedParams) error { |
| 57 | s.scheduleWorkspaceRebuild(ctx) |
| 58 | return nil |
| 59 | } |
| 60 | |
| 61 | func (s *server) Shutdown(ctx context.Context) error { |
| 62 | s.cancelWorkspaceRebuild() |
| 63 | return nil |
| 64 | } |
| 65 | |
| 66 | func (s *server) Exit(ctx context.Context) error { |
| 67 | return nil |
| 68 | } |