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