clerk/internal/lsp/server.go (view raw)
| 1 | package lsp |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "log/slog" |
| 6 | "sync" |
| 7 | |
| 8 | "go.lsp.dev/protocol" |
| 9 | "go.lsp.dev/uri" |
| 10 | |
| 11 | "olexsmir.xyz/clerk/internal/analyzer" |
| 12 | "olexsmir.xyz/clerk/internal/linter" |
| 13 | "olexsmir.xyz/clerk/journal" |
| 14 | "olexsmir.xyz/clerk/journal/printer" |
| 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 | printer *printer.Config |
| 28 | |
| 29 | mu sync.Mutex |
| 30 | openDocs map[uri.URI]docState |
| 31 | current *analyzer.Analysis |
| 32 | |
| 33 | diagMu sync.Mutex |
| 34 | diagCancel context.CancelFunc |
| 35 | } |
| 36 | |
| 37 | type docState struct { |
| 38 | text string |
| 39 | version int32 |
| 40 | languageID protocol.LanguageKind |
| 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: s.name, |
| 47 | Version: protocol.NewOptional(s.version), |
| 48 | }, |
| 49 | Capabilities: protocol.ServerCapabilities{ |
| 50 | DocumentFormattingProvider: &protocol.DocumentFormattingOptions{}, |
| 51 | TextDocumentSync: &protocol.TextDocumentSyncOptions{ |
| 52 | OpenClose: new(true), |
| 53 | Change: new(protocol.TextDocumentSyncKindFull), |
| 54 | }, |
| 55 | }, |
| 56 | }, nil |
| 57 | } |
| 58 | |
| 59 | func (s *server) Initialized(ctx context.Context, params *protocol.InitializedParams) error { |
| 60 | s.scheduleDiagnostics(ctx) |
| 61 | return nil |
| 62 | } |
| 63 | |
| 64 | func (s *server) Shutdown(ctx context.Context) error { |
| 65 | return nil |
| 66 | } |
| 67 | |
| 68 | func (s *server) Exit(ctx context.Context) error { |
| 69 | return nil |
| 70 | } |