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