diff --git a/go.mod b/go.mod index fd23d14..687cc2c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/kitagry/regols -go 1.19 +go 1.22 require ( github.com/google/go-cmp v0.6.0 diff --git a/langserver/completion.go b/langserver/completion.go index 1d2cc8b..f46aa1f 100644 --- a/langserver/completion.go +++ b/langserver/completion.go @@ -11,7 +11,7 @@ import ( "github.com/sourcegraph/jsonrpc2" ) -func (h *handler) handleTextDocumentCompletion(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) { +func (h *handler) handleTextDocumentCompletion(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) { if req.Params == nil { return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams} } diff --git a/langserver/definition.go b/langserver/definition.go index 988c2fd..ddca5e0 100644 --- a/langserver/definition.go +++ b/langserver/definition.go @@ -10,7 +10,7 @@ import ( "github.com/sourcegraph/jsonrpc2" ) -func (h *handler) handleTextDocumentDefinition(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) { +func (h *handler) handleTextDocumentDefinition(ctx context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) { if req.Params == nil { return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams} } @@ -23,7 +23,7 @@ func (h *handler) handleTextDocumentDefinition(ctx context.Context, conn *jsonrp return h.lookupIdent(ctx, params.TextDocument.URI, params.Position) } -func (h *handler) lookupIdent(ctx context.Context, uri lsp.DocumentURI, position lsp.Position) ([]lsp.Location, error) { +func (h *handler) lookupIdent(_ context.Context, uri lsp.DocumentURI, position lsp.Position) ([]lsp.Location, error) { loc := h.toOPALocation(position, uri) lookupResults, err := h.project.LookupDefinition(loc) if err != nil { diff --git a/langserver/diagnostic.go b/langserver/diagnostic.go index c94c576..be84b6d 100644 --- a/langserver/diagnostic.go +++ b/langserver/diagnostic.go @@ -10,12 +10,7 @@ import ( func (h *handler) diagnostic() { running := make(map[lsp.DocumentURI]context.CancelFunc) - for { - uri, ok := <-h.diagnosticRequest - if !ok { - break - } - + for uri := range h.diagnosticRequest { cancel, ok := running[uri] if ok { cancel() @@ -25,7 +20,7 @@ func (h *handler) diagnostic() { running[uri] = cancel go func() { - diagnostics, err := h.diagnose(ctx, uri) + diagnostics, err := h.diagnose(uri) if err != nil { h.logger.Println(err) return @@ -41,7 +36,7 @@ func (h *handler) diagnostic() { } } -func (h *handler) diagnose(ctx context.Context, uri lsp.DocumentURI) (map[lsp.DocumentURI][]lsp.Diagnostic, error) { +func (h *handler) diagnose(uri lsp.DocumentURI) (map[lsp.DocumentURI][]lsp.Diagnostic, error) { result := make(map[lsp.DocumentURI][]lsp.Diagnostic) pathToErrs := h.project.GetErrors(documentURIToURI(uri)) diff --git a/langserver/format.go b/langserver/format.go index c1fb1bb..332444b 100644 --- a/langserver/format.go +++ b/langserver/format.go @@ -11,7 +11,7 @@ import ( "github.com/sourcegraph/jsonrpc2" ) -func (h *handler) handleTextDocumentFormatting(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) { +func (h *handler) handleTextDocumentFormatting(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) { if req.Params == nil { return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams} } diff --git a/langserver/hover.go b/langserver/hover.go index 2aea136..7fee95a 100644 --- a/langserver/hover.go +++ b/langserver/hover.go @@ -8,7 +8,7 @@ import ( "github.com/sourcegraph/jsonrpc2" ) -func (h *handler) handleTextDocumentHover(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) { +func (h *handler) handleTextDocumentHover(ctx context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) { if req.Params == nil { return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams} } @@ -21,7 +21,7 @@ func (h *handler) handleTextDocumentHover(ctx context.Context, conn *jsonrpc2.Co return h.documentIdent(ctx, params.TextDocument.URI, params.Position) } -func (h *handler) documentIdent(ctx context.Context, uri lsp.DocumentURI, position lsp.Position) (lsp.Hover, error) { +func (h *handler) documentIdent(_ context.Context, uri lsp.DocumentURI, position lsp.Position) (lsp.Hover, error) { loc := h.toOPALocation(position, uri) documentResults, err := h.project.TermDocument(loc) if err != nil { diff --git a/langserver/initialize.go b/langserver/initialize.go index 8cfc60d..43701b3 100644 --- a/langserver/initialize.go +++ b/langserver/initialize.go @@ -9,7 +9,7 @@ import ( "github.com/sourcegraph/jsonrpc2" ) -func (h *handler) handleInitialize(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) { +func (h *handler) handleInitialize(_ context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) { if req.Params == nil { return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams} } @@ -31,7 +31,7 @@ func (h *handler) handleInitialize(ctx context.Context, conn *jsonrpc2.Conn, req return lsp.InitializeResult{ Capabilities: lsp.ServerCapabilities{ TextDocumentSync: &lsp.TextDocumentSyncOptionsOrKind{ - Kind: tdskToPTr(lsp.TDSKFull), + Kind: toPtr(lsp.TDSKFull), }, DocumentFormattingProvider: true, DefinitionProvider: true, @@ -45,6 +45,6 @@ func (h *handler) handleInitialize(ctx context.Context, conn *jsonrpc2.Conn, req }, nil } -func tdskToPTr(s lsp.TextDocumentSyncKind) *lsp.TextDocumentSyncKind { - return &s +func toPtr[T any](t T) *T { + return &t } diff --git a/langserver/internal/lsp/service.go b/langserver/internal/lsp/service.go index 4709029..c57ff82 100644 --- a/langserver/internal/lsp/service.go +++ b/langserver/internal/lsp/service.go @@ -24,7 +24,7 @@ type InitializeParams struct { RootURI DocumentURI `json:"rootUri,omitempty"` ClientInfo ClientInfo `json:"clientInfo,omitempty"` Trace Trace `json:"trace,omitempty"` - InitializationOptions interface{} `json:"initializationOptions,omitempty"` + InitializationOptions any `json:"initializationOptions,omitempty"` Capabilities ClientCapabilities `json:"capabilities"` WorkDoneToken string `json:"workDoneToken,omitempty"` @@ -54,7 +54,7 @@ type ClientCapabilities struct { Workspace WorkspaceClientCapabilities `json:"workspace,omitempty"` TextDocument TextDocumentClientCapabilities `json:"textDocument,omitempty"` Window WindowClientCapabilities `json:"window,omitempty"` - Experimental interface{} `json:"experimental,omitempty"` + Experimental any `json:"experimental,omitempty"` // Below are Sourcegraph extensions. They do not live in lspext since // they are extending the field InitializeParams.Capabilities @@ -196,7 +196,7 @@ type TextDocumentClientCapabilities struct { FoldingRange *struct { DynamicRegistration bool `json:"dynamicRegistration,omitempty"` - RangeLimit interface{} `json:"rangeLimit,omitempty"` + RangeLimit any `json:"rangeLimit,omitempty"` LineFoldingOnly bool `json:"lineFoldingOnly,omitempty"` } `json:"foldingRange,omitempty"` @@ -334,7 +334,7 @@ type ServerCapabilities struct { // is a Sourcegraph extension. XWorkspaceSymbolByProperties bool `json:"xworkspaceSymbolByProperties,omitempty"` - Experimental interface{} `json:"experimental,omitempty"` + Experimental any `json:"experimental,omitempty"` } type CompletionOptions struct { @@ -360,8 +360,8 @@ type ExecuteCommandOptions struct { } type ExecuteCommandParams struct { - Command string `json:"command"` - Arguments []interface{} `json:"arguments,omitempty"` + Command string `json:"command"` + Arguments []any `json:"arguments,omitempty"` } type SemanticHighlightingOptions struct { @@ -442,7 +442,7 @@ type CompletionItem struct { InsertTextFormat InsertTextFormat `json:"insertTextFormat,omitempty"` TextEdit *TextEdit `json:"textEdit,omitempty"` AdditionalTextEdits []TextEdit `json:"additionalTextEdits,omitempty"` - Data interface{} `json:"data,omitempty"` + Data any `json:"data,omitempty"` } type CompletionList struct { @@ -480,7 +480,7 @@ type InsertTextFormat int const ( ITFPlainText InsertTextFormat = 1 - ITFSnippet = 2 + ITFSnippet InsertTextFormat = 2 ) type CompletionContext struct { @@ -680,7 +680,7 @@ type ConfigurationItem struct { Section string `json:"section,omitempty"` } -type ConfigurationResult []interface{} +type ConfigurationResult []any type CodeActionContext struct { Diagnostics []Diagnostic `json:"diagnostics"` @@ -697,9 +697,9 @@ type CodeLensParams struct { } type CodeLens struct { - Range Range `json:"range"` - Command Command `json:"command,omitempty"` - Data interface{} `json:"data,omitempty"` + Range Range `json:"range"` + Command Command `json:"command,omitempty"` + Data any `json:"data,omitempty"` } type DocumentFormattingParams struct { @@ -772,7 +772,7 @@ type LogMessageParams struct { } type DidChangeConfigurationParams struct { - Settings interface{} `json:"settings"` + Settings any `json:"settings"` } type FileChangeType int diff --git a/langserver/internal/lsp/structure.go b/langserver/internal/lsp/structure.go index fa82feb..1f7a33f 100644 --- a/langserver/internal/lsp/structure.go +++ b/langserver/internal/lsp/structure.go @@ -95,7 +95,7 @@ type Command struct { * Arguments that the command handler should be * invoked with. */ - Arguments []interface{} `json:"arguments"` + Arguments []any `json:"arguments"` } type TextEdit struct { diff --git a/langserver/langserver.go b/langserver/langserver.go index 9734dae..c488877 100644 --- a/langserver/langserver.go +++ b/langserver/langserver.go @@ -30,7 +30,7 @@ func NewHandler() jsonrpc2.Handler { return jsonrpc2.HandlerWithError(handler.handle) } -func (h *handler) handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) { +func (h *handler) handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) { switch req.Method { case "initialize": return h.handleInitialize(ctx, conn, req) diff --git a/langserver/reference.go b/langserver/reference.go index b8286ed..754b70c 100644 --- a/langserver/reference.go +++ b/langserver/reference.go @@ -8,7 +8,7 @@ import ( "github.com/sourcegraph/jsonrpc2" ) -func (h *handler) handleTextDocumentReferences(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) { +func (h *handler) handleTextDocumentReferences(ctx context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) { if req.Params == nil { return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams} } @@ -21,7 +21,7 @@ func (h *handler) handleTextDocumentReferences(ctx context.Context, conn *jsonrp return h.lookupReferences(ctx, params.TextDocument.URI, params.Position) } -func (h *handler) lookupReferences(ctx context.Context, uri lsp.DocumentURI, position lsp.Position) ([]lsp.Location, error) { +func (h *handler) lookupReferences(_ context.Context, uri lsp.DocumentURI, position lsp.Position) ([]lsp.Location, error) { loc := h.toOPALocation(position, uri) locations, err := h.project.LookupReferences(loc) if err != nil { diff --git a/langserver/text_document.go b/langserver/text_document.go index db00130..4555fdf 100644 --- a/langserver/text_document.go +++ b/langserver/text_document.go @@ -8,7 +8,7 @@ import ( "github.com/sourcegraph/jsonrpc2" ) -func (h *handler) handleTextDocumentDidOpen(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) { +func (h *handler) handleTextDocumentDidOpen(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) { if req.Params == nil { return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams} } @@ -23,7 +23,7 @@ func (h *handler) handleTextDocumentDidOpen(ctx context.Context, conn *jsonrpc2. return nil, nil } -func (h *handler) handleTextDocumentDidChange(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) { +func (h *handler) handleTextDocumentDidChange(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) { if req.Params == nil { return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams} } @@ -38,7 +38,7 @@ func (h *handler) handleTextDocumentDidChange(ctx context.Context, conn *jsonrpc return nil, nil } -func (h *handler) handleTextDocumentDidClose(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) { +func (h *handler) handleTextDocumentDidClose(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) { if req.Params == nil { return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams} } @@ -53,7 +53,7 @@ func (h *handler) handleTextDocumentDidClose(ctx context.Context, conn *jsonrpc2 return nil, nil } -func (h *handler) handleTextDocumentDidSave(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request) (result interface{}, err error) { +func (h *handler) handleTextDocumentDidSave(_ context.Context, _ *jsonrpc2.Conn, req *jsonrpc2.Request) (result any, err error) { if req.Params == nil { return nil, &jsonrpc2.Error{Code: jsonrpc2.CodeInvalidParams} }