clerk/internal/lsp/server.go (view raw)
Oleksandr Smirnov
Oleksandr Smirnov
olexsmir@gmail.com linter/lsp: scope checks to include tree, 20 days ago
olexsmir@gmail.com linter/lsp: scope checks to include tree, 20 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/printer" |
| 15 | ) |
| 16 | |
| 17 | const name = "clerk" |
| 18 | |
| 19 | type docState struct { |
| 20 | text string |
| 21 | version int32 |
| 22 | languageID protocol.LanguageKind |
| 23 | } |
| 24 | |
| 25 | type server struct { |
| 26 | protocol.UnimplementedServer |
| 27 | |
| 28 | client protocol.Client |
| 29 | |
| 30 | version string |
| 31 | |
| 32 | printerCfg *printer.Config |
| 33 | logger *slog.Logger |
| 34 | |
| 35 | loader *journal.Loader |
| 36 | linter *linter.Linter |
| 37 | debouncer *time.Timer |
| 38 | |
| 39 | mu sync.Mutex |
| 40 | openDocs map[uri.URI]docState |
| 41 | } |
| 42 | |
| 43 | func (s *server) Initialize(ctx context.Context, params *protocol.InitializeParams) (*protocol.InitializeResult, error) { |
| 44 | return &protocol.InitializeResult{ |
| 45 | ServerInfo: protocol.ServerInfo{ |
| 46 | Name: name, |
| 47 | Version: protocol.NewOptional(s.version), |
| 48 | }, |
| 49 | Capabilities: protocol.ServerCapabilities{ |
| 50 | TextDocumentSync: &protocol.TextDocumentSyncOptions{ |
| 51 | OpenClose: new(true), |
| 52 | Change: new(protocol.TextDocumentSyncKindFull), |
| 53 | }, |
| 54 | DocumentFormattingProvider: &protocol.DocumentFormattingOptions{}, |
| 55 | // CompletionProvider: &protocol.CompletionOptions{ |
| 56 | // TriggerCharacters: []string{" ", ":", "/"}, |
| 57 | // }, |
| 58 | }, |
| 59 | }, nil |
| 60 | } |
| 61 | |
| 62 | func (s *server) Initialized(ctx context.Context, params *protocol.InitializedParams) error { |
| 63 | s.scheduleWorkspaceRebuild(ctx) |
| 64 | return nil |
| 65 | } |
| 66 | |
| 67 | func (s *server) Shutdown(ctx context.Context) error { |
| 68 | s.cancelWorkspaceRebuild() |
| 69 | return nil |
| 70 | } |
| 71 | |
| 72 | func (s *server) Exit(ctx context.Context) error { |
| 73 | return nil |
| 74 | } |