diff --git a/protocol_3_17/diagnostics.go b/protocol_3_17/diagnostics.go new file mode 100644 index 0000000..24c0069 --- /dev/null +++ b/protocol_3_17/diagnostics.go @@ -0,0 +1,227 @@ +package protocol + +import ( + "github.com/tliron/glsp" + protocol316 "github.com/tliron/glsp/protocol_3_16" +) + +/** + * Client capabilities specific to diagnostic pull requests. + * + * @since 3.17.0 + */ +type DiagnosticClientCapabilities struct { + /** + * Whether implementation supports dynamic registration. If this is set to + * `true` the client supports the new + * `(TextDocumentRegistrationOptions & StaticRegistrationOptions)` + * return value for the corresponding server capability as well. + */ + DynamicRegistration bool `json:"dynamicRegistration"` + + /** + * Whether the clients supports related documents for document diagnostic + * pulls. + */ + RelatedDocumentSupport bool `json:"relatedDocumentSupport"` +} + +/** + * Diagnostic options. + * + * @since 3.17.0 + */ +type DiagnosticOptions struct { + protocol316.WorkDoneProgressOptions + /** + * An optional identifier under which the diagnostics are + * managed by the client. + */ + Identifier *string `json:"identifier"` + + /** + * Whether the language has inter file dependencies meaning that + * editing code in one file can result in a different diagnostic + * set in another file. Inter file dependencies are common for + * most programming languages and typically uncommon for linters. + */ + InterFileDependencies bool `json:"interFileDependencies"` + + /** + * The server provides support for workspace diagnostics as well. + */ + WorkspaceDiagnostics bool `json:"workspaceDiagnostics"` +} + +/** + * Diagnostic registration options. + * + * @since 3.17.0 + */ +type DiagnosticRegistrationOptions struct { + protocol316.TextDocumentRegistrationOptions + DiagnosticOptions + protocol316.StaticRegistrationOptions +} + +const MethodTextDocumentDiagnostic = protocol316.Method("textDocument/diagnostic") + +type TextDocumentDiagnosticFunc func(context *glsp.Context, params *DocumentDiagnosticParams) (any, error) + +/** + * Parameters of the document diagnostic request. + * + * @since 3.17.0 + */ +type DocumentDiagnosticParams struct { + protocol316.WorkDoneProgressParams + protocol316.PartialResultParams + + /** + * The text document. + */ + TextDocument protocol316.TextDocumentIdentifier `json:"textDocument"` + + /** + * The additional identifier provided during registration. + */ + Identifier *string `json:"identifier,omitempty"` + + /** + * The result id of a previous response if provided. + */ + PreviousResultId *string `json:"previousResultId,omitempty"` +} + +/** + * The result of a document diagnostic pull request. A report can + * either be a full report containing all diagnostics for the + * requested document or a unchanged report indicating that nothing + * has changed in terms of diagnostics in comparison to the last + * pull request. + * + * @since 3.17.0 + */ +type DocumentDiagnosticReport any // RelatedFullDocumentDiagnosticReport | RelatedUnchangedDocumentDiagnosticReport + +/** + * The document diagnostic report kinds. + * + * @since 3.17.0 + */ +type DocumentDiagnosticReportKind string + +const ( + /** + * A diagnostic report with a full + * set of problems. + */ + DocumentDiagnosticReportKindFull = DocumentDiagnosticReportKind("full") + /** + * A report indicating that the last + * returned report is still accurate. + */ + DocumentDiagnosticReportKindUnchanged = DocumentDiagnosticReportKind("unchanged") +) + +/** + * A diagnostic report with a full set of problems. + * + * @since 3.17.0 + */ +type FullDocumentDiagnosticReport struct { + /** + * A full document diagnostic report. + */ + Kind string `json:"kind"` + + /** + * An optional result id. If provided it will + * be sent on the next diagnostic request for the + * same document. + */ + ResultID *string `json:"resultId,omitempty"` + + /** + * The actual items. + */ + Items []protocol316.Diagnostic `json:"items"` +} + +/** + * A diagnostic report indicating that the last returned + * report is still accurate. + * + * @since 3.17.0 + */ +type UnchangedDocumentDiagnosticReport struct { + /** + * A document diagnostic report indicating + * no changes to the last result. A server can + * only return `unchanged` if result ids are + * provided. + */ + Kind string `json:"kind"` + + /** + * A result id which will be sent on the next + * diagnostic request for the same document. + */ + ResultID string `json:"resultId"` +} + +/** + * A full diagnostic report with a set of related documents. + * + * @since 3.17.0 + */ +type RelatedFullDocumentDiagnosticReport struct { + FullDocumentDiagnosticReport + /** + * Diagnostics of related documents. This information is useful + * in programming languages where code in a file A can generate + * diagnostics in a file B which A depends on. An example of + * such a language is C/C++ where marco definitions in a file + * a.cpp and result in errors in a header file b.hpp. + * + * @since 3.17.0 + */ + RelatedDocuments map[protocol316.DocumentUri]interface{} `json:"relatedDocuments,omitempty"` +} + +/** + * An unchanged diagnostic report with a set of related documents. + * + * @since 3.17.0 + */ +type RelatedUnchangedDocumentDiagnosticReport struct { + UnchangedDocumentDiagnosticReport + /** + * Diagnostics of related documents. This information is useful + * in programming languages where code in a file A can generate + * diagnostics in a file B which A depends on. An example of + * such a language is C/C++ where marco definitions in a file + * a.cpp and result in errors in a header file b.hpp. + * + * @since 3.17.0 + */ + RelatedDocuments map[protocol316.DocumentUri]interface{} `json:"relatedDocuments,omitempty"` +} + +/** + * A partial result for a document diagnostic report. + * + * @since 3.17.0 + */ +type DocumentDiagnosticReportPartialResult struct { + RelatedDocuments map[protocol316.DocumentUri]interface{} `json:"relatedDocuments"` +} + +/** + * Cancellation data returned from a diagnostic request. + * + * @since 3.17.0 + */ +type DiagnosticServerCancellationData struct { + RetriggerRequest bool `json:"retriggerRequest"` +} diff --git a/protocol_3_17/general-messages.go b/protocol_3_17/general-messages.go new file mode 100644 index 0000000..8cd5970 --- /dev/null +++ b/protocol_3_17/general-messages.go @@ -0,0 +1,471 @@ +package protocol + +import ( + "encoding/json" + + "github.com/tliron/glsp" + protocol316 "github.com/tliron/glsp/protocol_3_16" +) + +// https://microsoft.github.io/language-server-protocol/specifications/specification-3-16#initialize + +const MethodInitialize = protocol316.Method("initialize") + +// Returns: InitializeResult | InitializeError +type InitializeFunc func(context *glsp.Context, params *InitializeParams) (any, error) + +type InitializeParams struct { + protocol316.InitializeParams + + /** + * The capabilities provided by the client (editor or tool) + */ + Capabilities ClientCapabilities `json:"capabilities"` +} + +type ClientCapabilities struct { + protocol316.ClientCapabilities + + TextDocument *TextDocumentClientCapabilities `json:"textDocument,omitempty"` +} + +/** + * Text document specific client capabilities. + */ +type TextDocumentClientCapabilities struct { + protocol316.TextDocumentClientCapabilities + + /** + * Capabilities specific to the diagnostic pull model. + * + * @since 3.17.0 + */ + Diagnostic *DiagnosticClientCapabilities `json:"diagnostic,omitempty"` +} + +type ServerCapabilities struct { + protocol316.ServerCapabilities + + /** + * The server has support for pull model diagnostics. + * + * @since 3.17.0 + */ + DiagnosticProvider any `json:"diagnosticProvider,omitempty"` // nil | DiagnosticOptions | DiagnosticRegistrationOptions +} + +func (self *ServerCapabilities) UnmarshalJSON(data []byte) error { + var value struct { + TextDocumentSync json.RawMessage `json:"textDocumentSync,omitempty"` // nil | TextDocumentSyncOptions | TextDocumentSyncKind + CompletionProvider *protocol316.CompletionOptions `json:"completionProvider,omitempty"` + HoverProvider json.RawMessage `json:"hoverProvider,omitempty"` // nil | bool | HoverOptions + SignatureHelpProvider *protocol316.SignatureHelpOptions `json:"signatureHelpProvider,omitempty"` + DeclarationProvider json.RawMessage `json:"declarationProvider,omitempty"` // nil | bool | DeclarationOptions | DeclarationRegistrationOptions + DefinitionProvider json.RawMessage `json:"definitionProvider,omitempty"` // nil | bool | DefinitionOptions + TypeDefinitionProvider json.RawMessage `json:"typeDefinitionProvider,omitempty"` // nil | bool | TypeDefinitionOption | TypeDefinitionRegistrationOptions + ImplementationProvider json.RawMessage `json:"implementationProvider,omitempty"` // nil | bool | ImplementationOptions | ImplementationRegistrationOptions + ReferencesProvider json.RawMessage `json:"referencesProvider,omitempty"` // nil | bool | ReferenceOptions + DocumentHighlightProvider json.RawMessage `json:"documentHighlightProvider,omitempty"` // nil | bool | DocumentHighlightOptions + DocumentSymbolProvider json.RawMessage `json:"documentSymbolProvider,omitempty"` // nil | bool | DocumentSymbolOptions + CodeActionProvider json.RawMessage `json:"codeActionProvider,omitempty"` // nil | bool | CodeActionOptions + CodeLensProvider *protocol316.CodeLensOptions `json:"codeLensProvider,omitempty"` + DocumentLinkProvider *protocol316.DocumentLinkOptions `json:"documentLinkProvider,omitempty"` + ColorProvider json.RawMessage `json:"colorProvider,omitempty"` // nil | bool | DocumentColorOptions | DocumentColorRegistrationOptions + DocumentFormattingProvider json.RawMessage `json:"documentFormattingProvider,omitempty"` // nil | bool | DocumentFormattingOptions + DocumentRangeFormattingProvider json.RawMessage `json:"documentRangeFormattingProvider,omitempty"` // nil | bool | DocumentRangeFormattingOptions + DocumentOnTypeFormattingProvider *protocol316.DocumentOnTypeFormattingOptions `json:"documentOnTypeFormattingProvider,omitempty"` + RenameProvider json.RawMessage `json:"renameProvider,omitempty"` // nil | bool | RenameOptions + FoldingRangeProvider json.RawMessage `json:"foldingRangeProvider,omitempty"` // nil | bool | FoldingRangeOptions | FoldingRangeRegistrationOptions + ExecuteCommandProvider *protocol316.ExecuteCommandOptions `json:"executeCommandProvider,omitempty"` + SelectionRangeProvider json.RawMessage `json:"selectionRangeProvider,omitempty"` // nil | bool | SelectionRangeOptions | SelectionRangeRegistrationOptions + LinkedEditingRangeProvider json.RawMessage `json:"linkedEditingRangeProvider,omitempty"` // nil | bool | LinkedEditingRangeOptions | LinkedEditingRangeRegistrationOptions + CallHierarchyProvider json.RawMessage `json:"callHierarchyProvider,omitempty"` // nil | bool | CallHierarchyOptions | CallHierarchyRegistrationOptions + SemanticTokensProvider json.RawMessage `json:"semanticTokensProvider,omitempty"` // nil | SemanticTokensOptions | SemanticTokensRegistrationOptions + MonikerProvider json.RawMessage `json:"monikerProvider,omitempty"` // nil | bool | MonikerOptions | MonikerRegistrationOptions + WorkspaceSymbolProvider json.RawMessage `json:"workspaceSymbolProvider,omitempty"` // nil | bool | WorkspaceSymbolOptions + Workspace *protocol316.ServerCapabilitiesWorkspace `json:"workspace,omitempty"` + Experimental *any `json:"experimental,omitempty"` + DiagnosticProvider json.RawMessage `json:"diagnosticProvider,omitempty"` // nil | DiagnosticOptions | DiagnosticRegistrationOptions + } + + if err := json.Unmarshal(data, &value); err == nil { + self.CompletionProvider = value.CompletionProvider + self.SignatureHelpProvider = value.SignatureHelpProvider + self.CodeLensProvider = value.CodeLensProvider + self.DocumentLinkProvider = value.DocumentLinkProvider + self.DocumentOnTypeFormattingProvider = value.DocumentOnTypeFormattingProvider + self.ExecuteCommandProvider = value.ExecuteCommandProvider + self.Workspace = value.Workspace + + if value.TextDocumentSync != nil { + var value_ protocol316.TextDocumentSyncOptions + if err = json.Unmarshal(value.TextDocumentSync, &value_); err == nil { + self.TextDocumentSync = value_ + } else { + var value_ protocol316.TextDocumentSyncKind + if err = json.Unmarshal(value.TextDocumentSync, &value_); err == nil { + self.TextDocumentSync = value_ + } else { + return err + } + } + } + + if value.HoverProvider != nil { + var value_ bool + if err = json.Unmarshal(value.HoverProvider, &value_); err == nil { + self.HoverProvider = value_ + } else { + var value_ protocol316.HoverOptions + if err = json.Unmarshal(value.HoverProvider, &value_); err == nil { + self.HoverProvider = value_ + } else { + return err + } + } + } + + if value.DeclarationProvider != nil { + var value_ bool + if err = json.Unmarshal(value.DeclarationProvider, &value_); err == nil { + self.DeclarationProvider = value_ + } else { + var value_ protocol316.DeclarationOptions + if err = json.Unmarshal(value.DeclarationProvider, &value_); err == nil { + self.DeclarationProvider = value_ + } else { + var value_ protocol316.DeclarationRegistrationOptions + if err = json.Unmarshal(value.DeclarationProvider, &value_); err == nil { + self.DeclarationProvider = value_ + } else { + return err + } + } + } + } + + if value.DefinitionProvider != nil { + var value_ bool + if err = json.Unmarshal(value.DefinitionProvider, &value_); err == nil { + self.DefinitionProvider = value_ + } else { + var value_ protocol316.DefinitionOptions + if err = json.Unmarshal(value.DefinitionProvider, &value_); err == nil { + self.DefinitionProvider = value_ + } else { + return err + } + } + } + + if value.TypeDefinitionProvider != nil { + var value_ bool + if err = json.Unmarshal(value.TypeDefinitionProvider, &value_); err == nil { + self.TypeDefinitionProvider = value_ + } else { + var value_ protocol316.TypeDefinitionOptions + if err = json.Unmarshal(value.TypeDefinitionProvider, &value_); err == nil { + self.TypeDefinitionProvider = value_ + } else { + var value_ protocol316.TypeDefinitionRegistrationOptions + if err = json.Unmarshal(value.TypeDefinitionProvider, &value_); err == nil { + self.TypeDefinitionProvider = value_ + } else { + return err + } + } + } + } + + if value.ImplementationProvider != nil { + var value_ bool + if err = json.Unmarshal(value.ImplementationProvider, &value_); err == nil { + self.ImplementationProvider = value_ + } else { + var value_ protocol316.ImplementationOptions + if err = json.Unmarshal(value.ImplementationProvider, &value_); err == nil { + self.ImplementationProvider = value_ + } else { + var value_ protocol316.ImplementationRegistrationOptions + if err = json.Unmarshal(value.ImplementationProvider, &value_); err == nil { + self.ImplementationProvider = value_ + } else { + return err + } + } + } + } + + if value.ReferencesProvider != nil { + var value_ bool + if err = json.Unmarshal(value.ReferencesProvider, &value_); err == nil { + self.ReferencesProvider = value_ + } else { + var value_ protocol316.ReferenceOptions + if err = json.Unmarshal(value.ReferencesProvider, &value_); err == nil { + self.ReferencesProvider = value_ + } else { + return err + } + } + } + + if value.DocumentHighlightProvider != nil { + var value_ bool + if err = json.Unmarshal(value.DocumentHighlightProvider, &value_); err == nil { + self.DocumentHighlightProvider = value_ + } else { + var value_ protocol316.DocumentHighlightOptions + if err = json.Unmarshal(value.DocumentHighlightProvider, &value_); err == nil { + self.DocumentHighlightProvider = value_ + } else { + return err + } + } + } + + if value.DocumentSymbolProvider != nil { + var value_ bool + if err = json.Unmarshal(value.DocumentSymbolProvider, &value_); err == nil { + self.DocumentSymbolProvider = value_ + } else { + var value_ protocol316.DocumentSymbolOptions + if err = json.Unmarshal(value.DocumentSymbolProvider, &value_); err == nil { + self.DocumentSymbolProvider = value_ + } else { + return err + } + } + } + + if value.CodeActionProvider != nil { + var value_ bool + if err = json.Unmarshal(value.CodeActionProvider, &value_); err == nil { + self.CodeActionProvider = value_ + } else { + var value_ protocol316.CodeActionOptions + if err = json.Unmarshal(value.CodeActionProvider, &value_); err == nil { + self.CodeActionProvider = value_ + } else { + return err + } + } + } + + if value.ColorProvider != nil { + var value_ bool + if err = json.Unmarshal(value.ColorProvider, &value_); err == nil { + self.ColorProvider = value_ + } else { + var value_ protocol316.DocumentColorOptions + if err = json.Unmarshal(value.ColorProvider, &value_); err == nil { + self.ColorProvider = value_ + } else { + var value_ protocol316.DocumentColorRegistrationOptions + if err = json.Unmarshal(value.ColorProvider, &value_); err == nil { + self.ColorProvider = value_ + } else { + return err + } + } + } + } + + if value.DocumentFormattingProvider != nil { + var value_ bool + if err = json.Unmarshal(value.DocumentFormattingProvider, &value_); err == nil { + self.DocumentFormattingProvider = value_ + } else { + var value_ protocol316.DocumentFormattingOptions + if err = json.Unmarshal(value.DocumentFormattingProvider, &value_); err == nil { + self.DocumentFormattingProvider = value_ + } else { + return err + } + } + } + + if value.DocumentRangeFormattingProvider != nil { + var value_ bool + if err = json.Unmarshal(value.DocumentRangeFormattingProvider, &value_); err == nil { + self.DocumentRangeFormattingProvider = value_ + } else { + var value_ protocol316.DocumentRangeFormattingOptions + if err = json.Unmarshal(value.DocumentRangeFormattingProvider, &value_); err == nil { + self.DocumentRangeFormattingProvider = value_ + } else { + return err + } + } + } + + if value.RenameProvider != nil { + var value_ bool + if err = json.Unmarshal(value.RenameProvider, &value_); err == nil { + self.RenameProvider = value_ + } else { + var value_ protocol316.RenameOptions + if err = json.Unmarshal(value.RenameProvider, &value_); err == nil { + self.RenameProvider = value_ + } else { + return err + } + } + } + + if value.FoldingRangeProvider != nil { + var value_ bool + if err = json.Unmarshal(value.FoldingRangeProvider, &value_); err == nil { + self.FoldingRangeProvider = value_ + } else { + var value_ protocol316.FoldingRangeOptions + if err = json.Unmarshal(value.FoldingRangeProvider, &value_); err == nil { + self.FoldingRangeProvider = value_ + } else { + var value_ protocol316.FoldingRangeRegistrationOptions + if err = json.Unmarshal(value.FoldingRangeProvider, &value_); err == nil { + self.FoldingRangeProvider = value_ + } else { + return err + } + } + } + } + + if value.SelectionRangeProvider != nil { + var value_ bool + if err = json.Unmarshal(value.SelectionRangeProvider, &value_); err == nil { + self.SelectionRangeProvider = value_ + } else { + var value_ protocol316.SelectionRangeOptions + if err = json.Unmarshal(value.SelectionRangeProvider, &value_); err == nil { + self.SelectionRangeProvider = value_ + } else { + var value_ protocol316.SelectionRangeRegistrationOptions + if err = json.Unmarshal(value.SelectionRangeProvider, &value_); err == nil { + self.SelectionRangeProvider = value_ + } else { + return err + } + } + } + } + + if value.LinkedEditingRangeProvider != nil { + var value_ bool + if err = json.Unmarshal(value.LinkedEditingRangeProvider, &value_); err == nil { + self.LinkedEditingRangeProvider = value_ + } else { + var value_ protocol316.LinkedEditingRangeOptions + if err = json.Unmarshal(value.LinkedEditingRangeProvider, &value_); err == nil { + self.LinkedEditingRangeProvider = value_ + } else { + var value_ protocol316.LinkedEditingRangeRegistrationOptions + if err = json.Unmarshal(value.LinkedEditingRangeProvider, &value_); err == nil { + self.LinkedEditingRangeProvider = value_ + } else { + return err + } + } + } + } + + if value.CallHierarchyProvider != nil { + var value_ bool + if err = json.Unmarshal(value.CallHierarchyProvider, &value_); err == nil { + self.CallHierarchyProvider = value_ + } else { + var value_ protocol316.CallHierarchyOptions + if err = json.Unmarshal(value.CallHierarchyProvider, &value_); err == nil { + self.CallHierarchyProvider = value_ + } else { + var value_ protocol316.CallHierarchyRegistrationOptions + if err = json.Unmarshal(value.CallHierarchyProvider, &value_); err == nil { + self.CallHierarchyProvider = value_ + } else { + return err + } + } + } + } + + if value.SemanticTokensProvider != nil { + var value_ protocol316.SemanticTokensOptions + if err = json.Unmarshal(value.SemanticTokensProvider, &value_); err == nil { + self.SemanticTokensProvider = value_ + } else { + var value_ protocol316.SemanticTokensRegistrationOptions + if err = json.Unmarshal(value.SemanticTokensProvider, &value_); err == nil { + self.SemanticTokensProvider = value_ + } else { + return err + } + } + } + + if value.MonikerProvider != nil { + var value_ bool + if err = json.Unmarshal(value.MonikerProvider, &value_); err == nil { + self.MonikerProvider = value_ + } else { + var value_ protocol316.MonikerOptions + if err = json.Unmarshal(value.MonikerProvider, &value_); err == nil { + self.MonikerProvider = value_ + } else { + var value_ protocol316.MonikerRegistrationOptions + if err = json.Unmarshal(value.MonikerProvider, &value_); err == nil { + self.MonikerProvider = value_ + } else { + return err + } + } + } + } + + if value.WorkspaceSymbolProvider != nil { + var value_ bool + if err = json.Unmarshal(value.WorkspaceSymbolProvider, &value_); err == nil { + self.WorkspaceSymbolProvider = value_ + } else { + var value_ protocol316.WorkspaceSymbolOptions + if err = json.Unmarshal(value.WorkspaceSymbolProvider, &value_); err == nil { + self.WorkspaceSymbolProvider = value_ + } else { + return err + } + } + } + + if value.DiagnosticProvider != nil { + var value_ DiagnosticOptions + if err = json.Unmarshal(value.DiagnosticProvider, &value_); err == nil { + self.DiagnosticProvider = value_ + } else { + var value_ DiagnosticRegistrationOptions + if err = json.Unmarshal(value.DiagnosticProvider, &value_); err == nil { + self.DiagnosticProvider = value_ + } else { + return err + } + } + } + + return nil + } else { + return err + } +} + +type InitializeResult struct { + /** + * The capabilities the language server provides. + */ + Capabilities ServerCapabilities `json:"capabilities"` + + /** + * Information about the server. + * + * @since 3.15.0 + */ + ServerInfo *protocol316.InitializeResultServerInfo `json:"serverInfo,omitempty"` +} diff --git a/protocol_3_17/handler.go b/protocol_3_17/handler.go new file mode 100644 index 0000000..5026a09 --- /dev/null +++ b/protocol_3_17/handler.go @@ -0,0 +1,912 @@ +package protocol + +import ( + "encoding/json" + "errors" + "sync" + + "github.com/tliron/glsp" + protocol316 "github.com/tliron/glsp/protocol_3_16" +) + +type Handler struct { + protocol316.Handler + + Initialize InitializeFunc + TextDocumentDiagnostic TextDocumentDiagnosticFunc + + initialized bool + lock sync.Mutex +} + +func (self *Handler) Handle(context *glsp.Context) (r any, validMethod bool, validParams bool, err error) { + if !self.IsInitialized() && (context.Method != protocol316.MethodInitialize) { + return nil, true, true, errors.New("server not initialized") + } + + switch context.Method { + case protocol316.MethodCancelRequest: + if self.CancelRequest != nil { + validMethod = true + var params protocol316.CancelParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.CancelRequest(context, ¶ms) + } + } + + case protocol316.MethodProgress: + if self.Progress != nil { + validMethod = true + var params protocol316.ProgressParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.Progress(context, ¶ms) + } + } + + // General Messages + + case MethodInitialize: + if self.Initialize != nil { + validMethod = true + var params InitializeParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + if r, err = self.Initialize(context, ¶ms); err == nil { + self.SetInitialized(true) + } + } + } + + case protocol316.MethodInitialized: + if self.Initialized != nil { + validMethod = true + var params protocol316.InitializedParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.Initialized(context, ¶ms) + } + } + + case protocol316.MethodShutdown: + self.SetInitialized(false) + if self.Shutdown != nil { + validMethod = true + validParams = true + err = self.Shutdown(context) + } + + case protocol316.MethodExit: + // Note that the server will close the connection after we handle it here + if self.Exit != nil { + validMethod = true + validParams = true + err = self.Exit(context) + } + + case protocol316.MethodLogTrace: + if self.LogTrace != nil { + validMethod = true + var params protocol316.LogTraceParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.LogTrace(context, ¶ms) + } + } + + case protocol316.MethodSetTrace: + if self.SetTrace != nil { + validMethod = true + var params protocol316.SetTraceParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.SetTrace(context, ¶ms) + } + } + + // Window + + case protocol316.MethodWindowWorkDoneProgressCancel: + if self.WindowWorkDoneProgressCancel != nil { + validMethod = true + var params protocol316.WorkDoneProgressCancelParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.WindowWorkDoneProgressCancel(context, ¶ms) + } + } + + // Workspace + + case protocol316.MethodWorkspaceDidChangeWorkspaceFolders: + if self.WorkspaceDidChangeWorkspaceFolders != nil { + validMethod = true + var params protocol316.DidChangeWorkspaceFoldersParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.WorkspaceDidChangeWorkspaceFolders(context, ¶ms) + } + } + + case protocol316.MethodWorkspaceDidChangeConfiguration: + if self.WorkspaceDidChangeConfiguration != nil { + validMethod = true + var params protocol316.DidChangeConfigurationParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.WorkspaceDidChangeConfiguration(context, ¶ms) + } + } + + case protocol316.MethodWorkspaceDidChangeWatchedFiles: + if self.WorkspaceDidChangeWatchedFiles != nil { + validMethod = true + var params protocol316.DidChangeWatchedFilesParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.WorkspaceDidChangeWatchedFiles(context, ¶ms) + } + } + + case protocol316.MethodWorkspaceSymbol: + if self.WorkspaceSymbol != nil { + validMethod = true + var params protocol316.WorkspaceSymbolParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.WorkspaceSymbol(context, ¶ms) + } + } + + case protocol316.MethodWorkspaceExecuteCommand: + if self.WorkspaceExecuteCommand != nil { + validMethod = true + var params protocol316.ExecuteCommandParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.WorkspaceExecuteCommand(context, ¶ms) + } + } + + case protocol316.MethodWorkspaceWillCreateFiles: + if self.WorkspaceWillCreateFiles != nil { + validMethod = true + var params protocol316.CreateFilesParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.WorkspaceWillCreateFiles(context, ¶ms) + } + } + + case protocol316.MethodWorkspaceDidCreateFiles: + if self.WorkspaceDidCreateFiles != nil { + validMethod = true + var params protocol316.CreateFilesParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.WorkspaceDidCreateFiles(context, ¶ms) + } + } + + case protocol316.MethodWorkspaceWillRenameFiles: + if self.WorkspaceWillRenameFiles != nil { + validMethod = true + var params protocol316.RenameFilesParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.WorkspaceWillRenameFiles(context, ¶ms) + } + } + + case protocol316.MethodWorkspaceDidRenameFiles: + if self.WorkspaceDidRenameFiles != nil { + validMethod = true + var params protocol316.RenameFilesParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.WorkspaceDidRenameFiles(context, ¶ms) + } + } + + case protocol316.MethodWorkspaceWillDeleteFiles: + if self.WorkspaceWillDeleteFiles != nil { + validMethod = true + var params protocol316.DeleteFilesParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.WorkspaceWillDeleteFiles(context, ¶ms) + } + } + + case protocol316.MethodWorkspaceDidDeleteFiles: + if self.WorkspaceDidDeleteFiles != nil { + validMethod = true + var params protocol316.DeleteFilesParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.WorkspaceDidDeleteFiles(context, ¶ms) + } + } + + // Text Document Synchronization + + case protocol316.MethodTextDocumentDidOpen: + if self.TextDocumentDidOpen != nil { + validMethod = true + var params protocol316.DidOpenTextDocumentParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.TextDocumentDidOpen(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentDidChange: + if self.TextDocumentDidChange != nil { + validMethod = true + var params protocol316.DidChangeTextDocumentParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.TextDocumentDidChange(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentWillSave: + if self.TextDocumentWillSave != nil { + validMethod = true + var params protocol316.WillSaveTextDocumentParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.TextDocumentWillSave(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentWillSaveWaitUntil: + if self.TextDocumentWillSaveWaitUntil != nil { + validMethod = true + var params protocol316.WillSaveTextDocumentParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentWillSaveWaitUntil(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentDidSave: + if self.TextDocumentDidSave != nil { + validMethod = true + var params protocol316.DidSaveTextDocumentParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.TextDocumentDidSave(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentDidClose: + if self.TextDocumentDidClose != nil { + validMethod = true + var params protocol316.DidCloseTextDocumentParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + err = self.TextDocumentDidClose(context, ¶ms) + } + } + + // Language Features + + case protocol316.MethodTextDocumentCompletion: + if self.TextDocumentCompletion != nil { + validMethod = true + var params protocol316.CompletionParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentCompletion(context, ¶ms) + } + } + + case protocol316.MethodCompletionItemResolve: + if self.CompletionItemResolve != nil { + validMethod = true + var params protocol316.CompletionItem + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.CompletionItemResolve(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentHover: + if self.TextDocumentHover != nil { + validMethod = true + var params protocol316.HoverParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentHover(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentSignatureHelp: + if self.TextDocumentSignatureHelp != nil { + validMethod = true + var params protocol316.SignatureHelpParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentSignatureHelp(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentDeclaration: + if self.TextDocumentDeclaration != nil { + validMethod = true + var params protocol316.DeclarationParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentDeclaration(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentDefinition: + if self.TextDocumentDefinition != nil { + validMethod = true + var params protocol316.DefinitionParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentDefinition(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentTypeDefinition: + if self.TextDocumentTypeDefinition != nil { + validMethod = true + var params protocol316.TypeDefinitionParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentTypeDefinition(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentImplementation: + if self.TextDocumentImplementation != nil { + validMethod = true + var params protocol316.ImplementationParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentImplementation(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentReferences: + if self.TextDocumentReferences != nil { + validMethod = true + var params protocol316.ReferenceParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentReferences(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentDocumentHighlight: + if self.TextDocumentDocumentHighlight != nil { + validMethod = true + var params protocol316.DocumentHighlightParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentDocumentHighlight(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentDocumentSymbol: + if self.TextDocumentDocumentSymbol != nil { + validMethod = true + var params protocol316.DocumentSymbolParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentDocumentSymbol(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentCodeAction: + if self.TextDocumentCodeAction != nil { + validMethod = true + var params protocol316.CodeActionParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentCodeAction(context, ¶ms) + } + } + + case protocol316.MethodCodeActionResolve: + if self.CodeActionResolve != nil { + validMethod = true + var params protocol316.CodeAction + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.CodeActionResolve(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentCodeLens: + if self.TextDocumentCodeLens != nil { + validMethod = true + var params protocol316.CodeLensParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentCodeLens(context, ¶ms) + } + } + + case protocol316.MethodCodeLensResolve: + if self.TextDocumentDidClose != nil { + validMethod = true + var params protocol316.CodeLens + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.CodeLensResolve(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentDocumentLink: + if self.TextDocumentDocumentLink != nil { + validMethod = true + var params protocol316.DocumentLinkParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentDocumentLink(context, ¶ms) + } + } + + case protocol316.MethodDocumentLinkResolve: + if self.DocumentLinkResolve != nil { + validMethod = true + var params protocol316.DocumentLink + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.DocumentLinkResolve(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentColor: + if self.TextDocumentColor != nil { + validMethod = true + var params protocol316.DocumentColorParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentColor(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentColorPresentation: + if self.TextDocumentColorPresentation != nil { + validMethod = true + var params protocol316.ColorPresentationParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentColorPresentation(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentFormatting: + if self.TextDocumentFormatting != nil { + validMethod = true + var params protocol316.DocumentFormattingParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentFormatting(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentRangeFormatting: + if self.TextDocumentRangeFormatting != nil { + validMethod = true + var params protocol316.DocumentRangeFormattingParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentRangeFormatting(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentOnTypeFormatting: + if self.TextDocumentOnTypeFormatting != nil { + validMethod = true + var params protocol316.DocumentOnTypeFormattingParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentOnTypeFormatting(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentRename: + if self.TextDocumentRename != nil { + validMethod = true + var params protocol316.RenameParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentRename(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentPrepareRename: + if self.TextDocumentPrepareRename != nil { + validMethod = true + var params protocol316.PrepareRenameParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentPrepareRename(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentFoldingRange: + if self.TextDocumentFoldingRange != nil { + validMethod = true + var params protocol316.FoldingRangeParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentFoldingRange(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentSelectionRange: + if self.TextDocumentSelectionRange != nil { + validMethod = true + var params protocol316.SelectionRangeParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentSelectionRange(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentPrepareCallHierarchy: + if self.TextDocumentPrepareCallHierarchy != nil { + validMethod = true + var params protocol316.CallHierarchyPrepareParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentPrepareCallHierarchy(context, ¶ms) + } + } + + case protocol316.MethodCallHierarchyIncomingCalls: + if self.CallHierarchyIncomingCalls != nil { + validMethod = true + var params protocol316.CallHierarchyIncomingCallsParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.CallHierarchyIncomingCalls(context, ¶ms) + } + } + + case protocol316.MethodCallHierarchyOutgoingCalls: + if self.CallHierarchyOutgoingCalls != nil { + validMethod = true + var params protocol316.CallHierarchyOutgoingCallsParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.CallHierarchyOutgoingCalls(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentSemanticTokensFull: + if self.TextDocumentSemanticTokensFull != nil { + validMethod = true + var params protocol316.SemanticTokensParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentSemanticTokensFull(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentSemanticTokensFullDelta: + if self.TextDocumentSemanticTokensFullDelta != nil { + validMethod = true + var params protocol316.SemanticTokensDeltaParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentSemanticTokensFullDelta(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentSemanticTokensRange: + if self.TextDocumentSemanticTokensRange != nil { + validMethod = true + var params protocol316.SemanticTokensRangeParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentSemanticTokensRange(context, ¶ms) + } + } + + case protocol316.MethodWorkspaceSemanticTokensRefresh: + if self.WorkspaceSemanticTokensRefresh != nil { + validMethod = true + validParams = true + err = self.WorkspaceSemanticTokensRefresh(context) + } + + case protocol316.MethodTextDocumentLinkedEditingRange: + if self.TextDocumentLinkedEditingRange != nil { + validMethod = true + var params protocol316.LinkedEditingRangeParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentLinkedEditingRange(context, ¶ms) + } + } + + case protocol316.MethodTextDocumentMoniker: + if self.TextDocumentMoniker != nil { + validMethod = true + var params protocol316.MonikerParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentMoniker(context, ¶ms) + } + } + case MethodTextDocumentDiagnostic: + if self.TextDocumentDiagnostic != nil { + validMethod = true + var params DocumentDiagnosticParams + if err = json.Unmarshal(context.Params, ¶ms); err == nil { + validParams = true + r, err = self.TextDocumentDiagnostic(context, ¶ms) + } + } + } + + return + +} + +func (self *Handler) IsInitialized() bool { + self.lock.Lock() + defer self.lock.Unlock() + return self.initialized +} + +func (self *Handler) SetInitialized(initialized bool) { + self.lock.Lock() + defer self.lock.Unlock() + self.initialized = initialized +} + +func (self *Handler) CreateServerCapabilities() ServerCapabilities { + var capabilities ServerCapabilities + + if (self.TextDocumentDidOpen != nil) || (self.TextDocumentDidClose != nil) { + if _, ok := capabilities.TextDocumentSync.(*protocol316.TextDocumentSyncOptions); !ok { + capabilities.TextDocumentSync = &protocol316.TextDocumentSyncOptions{} + } + capabilities.TextDocumentSync.(*protocol316.TextDocumentSyncOptions).OpenClose = &protocol316.True + } + + if self.TextDocumentDidChange != nil { + if _, ok := capabilities.TextDocumentSync.(*protocol316.TextDocumentSyncOptions); !ok { + capabilities.TextDocumentSync = &protocol316.TextDocumentSyncOptions{} + } + // This can be overriden to TextDocumentSyncKindFull + value := protocol316.TextDocumentSyncKindIncremental + capabilities.TextDocumentSync.(*protocol316.TextDocumentSyncOptions).Change = &value + } + + if self.TextDocumentWillSave != nil { + if _, ok := capabilities.TextDocumentSync.(*protocol316.TextDocumentSyncOptions); !ok { + capabilities.TextDocumentSync = &protocol316.TextDocumentSyncOptions{} + } + capabilities.TextDocumentSync.(*protocol316.TextDocumentSyncOptions).WillSave = &protocol316.True + } + + if self.TextDocumentWillSaveWaitUntil != nil { + if _, ok := capabilities.TextDocumentSync.(*protocol316.TextDocumentSyncOptions); !ok { + capabilities.TextDocumentSync = &protocol316.TextDocumentSyncOptions{} + } + capabilities.TextDocumentSync.(*protocol316.TextDocumentSyncOptions).WillSaveWaitUntil = &protocol316.True + } + + if self.TextDocumentDidSave != nil { + if _, ok := capabilities.TextDocumentSync.(*protocol316.TextDocumentSyncOptions); !ok { + capabilities.TextDocumentSync = &protocol316.TextDocumentSyncOptions{} + } + capabilities.TextDocumentSync.(*protocol316.TextDocumentSyncOptions).Save = &protocol316.True + } + + if self.TextDocumentCompletion != nil { + capabilities.CompletionProvider = &protocol316.CompletionOptions{} + } + + if self.TextDocumentHover != nil { + capabilities.HoverProvider = true + } + + if self.TextDocumentSignatureHelp != nil { + capabilities.SignatureHelpProvider = &protocol316.SignatureHelpOptions{} + } + + if self.TextDocumentDeclaration != nil { + capabilities.DeclarationProvider = true + } + + if self.TextDocumentDefinition != nil { + capabilities.DefinitionProvider = true + } + + if self.TextDocumentTypeDefinition != nil { + capabilities.TypeDefinitionProvider = true + } + + if self.TextDocumentImplementation != nil { + capabilities.ImplementationProvider = true + } + + if self.TextDocumentReferences != nil { + capabilities.ReferencesProvider = true + } + + if self.TextDocumentDocumentHighlight != nil { + capabilities.DocumentHighlightProvider = true + } + + if self.TextDocumentDocumentSymbol != nil { + capabilities.DocumentSymbolProvider = true + } + + if self.TextDocumentCodeAction != nil { + capabilities.CodeActionProvider = true + } + + if self.TextDocumentCodeLens != nil { + capabilities.CodeLensProvider = &protocol316.CodeLensOptions{} + } + + if self.TextDocumentDocumentLink != nil { + capabilities.DocumentLinkProvider = &protocol316.DocumentLinkOptions{} + } + + if self.TextDocumentColor != nil { + capabilities.ColorProvider = true + } + + if self.TextDocumentFormatting != nil { + capabilities.DocumentFormattingProvider = true + } + + if self.TextDocumentRangeFormatting != nil { + capabilities.DocumentRangeFormattingProvider = true + } + + if self.TextDocumentOnTypeFormatting != nil { + capabilities.DocumentOnTypeFormattingProvider = &protocol316.DocumentOnTypeFormattingOptions{} + } + + if self.TextDocumentRename != nil { + capabilities.RenameProvider = true + } + + if self.TextDocumentFoldingRange != nil { + capabilities.FoldingRangeProvider = true + } + + if self.WorkspaceExecuteCommand != nil { + capabilities.ExecuteCommandProvider = &protocol316.ExecuteCommandOptions{} + } + + if self.TextDocumentSelectionRange != nil { + capabilities.SelectionRangeProvider = true + } + + if self.TextDocumentLinkedEditingRange != nil { + capabilities.LinkedEditingRangeProvider = true + } + + if self.TextDocumentPrepareCallHierarchy != nil { + capabilities.CallHierarchyProvider = true + } + + if self.TextDocumentSemanticTokensFull != nil { + if _, ok := capabilities.SemanticTokensProvider.(*protocol316.SemanticTokensOptions); !ok { + capabilities.SemanticTokensProvider = &protocol316.SemanticTokensOptions{} + } + if self.TextDocumentSemanticTokensFullDelta != nil { + capabilities.SemanticTokensProvider.(*protocol316.SemanticTokensOptions).Full = &protocol316.SemanticDelta{} + capabilities.SemanticTokensProvider.(*protocol316.SemanticTokensOptions).Full.(*protocol316.SemanticDelta).Delta = &protocol316.True + } else { + capabilities.SemanticTokensProvider.(*protocol316.SemanticTokensOptions).Full = true + } + } + + if self.TextDocumentSemanticTokensRange != nil { + if _, ok := capabilities.SemanticTokensProvider.(*protocol316.SemanticTokensOptions); !ok { + capabilities.SemanticTokensProvider = &protocol316.SemanticTokensOptions{} + } + capabilities.SemanticTokensProvider.(*protocol316.SemanticTokensOptions).Range = true + } + + // TODO: self.TextDocumentSemanticTokensRefresh? + + if self.TextDocumentMoniker != nil { + capabilities.MonikerProvider = true + } + + if self.WorkspaceSymbol != nil { + capabilities.WorkspaceSymbolProvider = true + } + + if self.WorkspaceDidCreateFiles != nil { + if capabilities.Workspace == nil { + capabilities.Workspace = &protocol316.ServerCapabilitiesWorkspace{} + } + if capabilities.Workspace.FileOperations == nil { + capabilities.Workspace.FileOperations = &protocol316.ServerCapabilitiesWorkspaceFileOperations{} + } + capabilities.Workspace.FileOperations.DidCreate = &protocol316.FileOperationRegistrationOptions{ + Filters: []protocol316.FileOperationFilter{}, + } + } + + if self.WorkspaceWillCreateFiles != nil { + if capabilities.Workspace == nil { + capabilities.Workspace = &protocol316.ServerCapabilitiesWorkspace{} + } + if capabilities.Workspace.FileOperations == nil { + capabilities.Workspace.FileOperations = &protocol316.ServerCapabilitiesWorkspaceFileOperations{} + } + capabilities.Workspace.FileOperations.WillCreate = &protocol316.FileOperationRegistrationOptions{ + Filters: []protocol316.FileOperationFilter{}, + } + } + + if self.WorkspaceDidRenameFiles != nil { + capabilities.RenameProvider = true + if capabilities.Workspace == nil { + capabilities.Workspace = &protocol316.ServerCapabilitiesWorkspace{} + } + if capabilities.Workspace.FileOperations == nil { + capabilities.Workspace.FileOperations = &protocol316.ServerCapabilitiesWorkspaceFileOperations{} + } + capabilities.Workspace.FileOperations.DidRename = &protocol316.FileOperationRegistrationOptions{ + Filters: []protocol316.FileOperationFilter{}, + } + } + + if self.WorkspaceWillRenameFiles != nil { + capabilities.RenameProvider = true + if capabilities.Workspace == nil { + capabilities.Workspace = &protocol316.ServerCapabilitiesWorkspace{} + } + if capabilities.Workspace.FileOperations == nil { + capabilities.Workspace.FileOperations = &protocol316.ServerCapabilitiesWorkspaceFileOperations{} + } + capabilities.Workspace.FileOperations.WillRename = &protocol316.FileOperationRegistrationOptions{ + Filters: []protocol316.FileOperationFilter{}, + } + } + + if self.WorkspaceDidDeleteFiles != nil { + if capabilities.Workspace == nil { + capabilities.Workspace = &protocol316.ServerCapabilitiesWorkspace{} + } + if capabilities.Workspace.FileOperations == nil { + capabilities.Workspace.FileOperations = &protocol316.ServerCapabilitiesWorkspaceFileOperations{} + } + capabilities.Workspace.FileOperations.DidDelete = &protocol316.FileOperationRegistrationOptions{ + Filters: []protocol316.FileOperationFilter{}, + } + } + + if self.WorkspaceWillDeleteFiles != nil { + if capabilities.Workspace == nil { + capabilities.Workspace = &protocol316.ServerCapabilitiesWorkspace{} + } + if capabilities.Workspace.FileOperations == nil { + capabilities.Workspace.FileOperations = &protocol316.ServerCapabilitiesWorkspaceFileOperations{} + } + capabilities.Workspace.FileOperations.WillDelete = &protocol316.FileOperationRegistrationOptions{ + Filters: []protocol316.FileOperationFilter{}, + } + } + + if self.TextDocumentDiagnostic != nil { + capabilities.DiagnosticProvider = DiagnosticOptions{ + InterFileDependencies: true, + WorkspaceDiagnostics: false, + } + } + + return capabilities +}