From ece38e2e7395333215831c1745fde1afc6daee3c Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Thu, 19 Nov 2020 11:14:11 +0000 Subject: [PATCH] Reflect differences between the two libraries --- commands/completion_command.go | 2 +- internal/lsp/completion.go | 63 ++++++++------------------ internal/lsp/diagnostics.go | 4 +- internal/lsp/file.go | 2 +- internal/lsp/file_change.go | 13 ------ internal/lsp/file_handler.go | 2 +- internal/lsp/hover.go | 20 ++++---- internal/lsp/markup_content.go | 25 ++++++++++ internal/lsp/position.go | 8 ++-- internal/lsp/range.go | 24 +++++----- internal/lsp/symbols.go | 2 +- internal/lsp/text_edits.go | 52 +++++++++++++++++++++ langserver/handlers/cancel_request.go | 18 +++++++- langserver/handlers/complete.go | 4 +- langserver/handlers/did_change.go | 34 ++------------ langserver/handlers/did_open.go | 4 +- langserver/handlers/execute_command.go | 9 ++-- langserver/handlers/formatting.go | 2 +- langserver/handlers/handlers_test.go | 43 ++++++++++-------- langserver/handlers/hover_test.go | 7 +-- langserver/handlers/initialize.go | 16 +++---- langserver/handlers/initialized.go | 2 +- langserver/handlers/shutdown.go | 4 +- 23 files changed, 195 insertions(+), 165 deletions(-) create mode 100644 internal/lsp/markup_content.go create mode 100644 internal/lsp/text_edits.go diff --git a/commands/completion_command.go b/commands/completion_command.go index f6c81a3e7..bebf5ef95 100644 --- a/commands/completion_command.go +++ b/commands/completion_command.go @@ -77,7 +77,7 @@ func (c *CompletionCommand) Run(args []string) int { c.Ui.Error(fmt.Sprintf("Error parsing column: %s (expected number)", err)) return 1 } - lspPos := lsp.Position{Line: line, Character: col} + lspPos := lsp.Position{Line: float64(line), Character: float64(col)} logger := logging.NewLogger(os.Stderr) diff --git a/internal/lsp/completion.go b/internal/lsp/completion.go index 949dd6285..97d0fc7a4 100644 --- a/internal/lsp/completion.go +++ b/internal/lsp/completion.go @@ -6,19 +6,9 @@ import ( lsp "github.com/hashicorp/terraform-ls/internal/protocol" ) -type CompletionList struct { - IsIncomplete bool `json:"isIncomplete"` - Items []CompletionItem `json:"items"` -} - -type CompletionItem struct { - lsp.CompletionItem - Command *lsp.Command `json:"command,omitempty"` -} - -func ToCompletionList(candidates lang.Candidates, caps lsp.TextDocumentClientCapabilities) CompletionList { - list := CompletionList{ - Items: make([]CompletionItem, len(candidates.List)), +func ToCompletionList(candidates lang.Candidates, caps lsp.TextDocumentClientCapabilities) lsp.CompletionList { + list := lsp.CompletionList{ + Items: make([]lsp.CompletionItem, len(candidates.List)), IsIncomplete: !candidates.IsComplete, } @@ -26,7 +16,7 @@ func ToCompletionList(candidates lang.Candidates, caps lsp.TextDocumentClientCap markdown := false docsFormat := caps.Completion.CompletionItem.DocumentationFormat - if len(docsFormat) > 0 && docsFormat[0] == "markdown" { + if len(docsFormat) > 0 && docsFormat[0] == lsp.Markdown { markdown = true } @@ -37,23 +27,23 @@ func ToCompletionList(candidates lang.Candidates, caps lsp.TextDocumentClientCap return list } -func toCompletionItem(candidate lang.Candidate, snippet, markdown bool) CompletionItem { +func toCompletionItem(candidate lang.Candidate, snippet, markdown bool) lsp.CompletionItem { doc := candidate.Description.Value - // TODO: revisit once go-lsp supports markdown in CompletionItem + // TODO: Revisit when MarkupContent is allowed as Documentation + // https://github.com/golang/tools/blob/4783bc9b/internal/lsp/protocol/tsprotocol.go#L753 doc = mdplain.Clean(doc) var kind lsp.CompletionItemKind switch candidate.Kind { case lang.AttributeCandidateKind: - kind = lsp.CIKProperty + kind = lsp.PropertyCompletion case lang.BlockCandidateKind: - kind = lsp.CIKClass + kind = lsp.ClassCompletion case lang.LabelCandidateKind: - kind = lsp.CIKField + kind = lsp.FieldCompletion } - te, format := textEdit(candidate.TextEdit, snippet) var cmd *lsp.Command if candidate.TriggerSuggest { cmd = &lsp.Command{ @@ -62,29 +52,14 @@ func toCompletionItem(candidate lang.Candidate, snippet, markdown bool) Completi } } - return CompletionItem{ - CompletionItem: lsp.CompletionItem{ - Label: candidate.Label, - Kind: kind, - InsertTextFormat: format, - Detail: candidate.Detail, - Documentation: doc, - TextEdit: te, - }, - Command: cmd, + return lsp.CompletionItem{ + Label: candidate.Label, + Kind: kind, + InsertTextFormat: insertTextFormat(snippet), + Detail: candidate.Detail, + Documentation: doc, + TextEdit: textEdit(candidate.TextEdit, snippet), + Command: cmd, + AdditionalTextEdits: textEdits(candidate.AdditionalTextEdits, snippet), } } - -func textEdit(te lang.TextEdit, snippetSupport bool) (*lsp.TextEdit, lsp.InsertTextFormat) { - if snippetSupport { - return &lsp.TextEdit{ - NewText: te.Snippet, - Range: HCLRangeToLSP(te.Range), - }, lsp.ITFSnippet - } - - return &lsp.TextEdit{ - NewText: te.NewText, - Range: HCLRangeToLSP(te.Range), - }, lsp.ITFPlainText -} diff --git a/internal/lsp/diagnostics.go b/internal/lsp/diagnostics.go index 16165b890..1b1bbbc70 100644 --- a/internal/lsp/diagnostics.go +++ b/internal/lsp/diagnostics.go @@ -9,9 +9,9 @@ func HCLSeverityToLSP(severity hcl.DiagnosticSeverity) lsp.DiagnosticSeverity { var sev lsp.DiagnosticSeverity switch severity { case hcl.DiagError: - sev = lsp.Error + sev = lsp.SeverityError case hcl.DiagWarning: - sev = lsp.Warning + sev = lsp.SeverityWarning case hcl.DiagInvalid: panic("invalid diagnostic") } diff --git a/internal/lsp/file.go b/internal/lsp/file.go index 5f43a5f74..fd4e9c2f7 100644 --- a/internal/lsp/file.go +++ b/internal/lsp/file.go @@ -59,6 +59,6 @@ func FileFromDocumentItem(doc lsp.TextDocumentItem) *file { return &file{ fh: FileHandlerFromDocumentURI(doc.URI), text: []byte(doc.Text), - version: doc.Version, + version: int(doc.Version), } } diff --git a/internal/lsp/file_change.go b/internal/lsp/file_change.go index 5870fcb28..3bd8b7034 100644 --- a/internal/lsp/file_change.go +++ b/internal/lsp/file_change.go @@ -26,19 +26,6 @@ func DocumentChanges(events []lsp.TextDocumentContentChangeEvent, f File) (files return changes, nil } -func TextEdits(changes filesystem.DocumentChanges) []lsp.TextEdit { - edits := make([]lsp.TextEdit, len(changes)) - - for i, change := range changes { - edits[i] = lsp.TextEdit{ - Range: fsRangeToLSP(change.Range()), - NewText: change.Text(), - } - } - - return edits -} - func (fc *contentChange) Text() string { return fc.text } diff --git a/internal/lsp/file_handler.go b/internal/lsp/file_handler.go index 688ec1300..573e1e03e 100644 --- a/internal/lsp/file_handler.go +++ b/internal/lsp/file_handler.go @@ -86,7 +86,7 @@ type versionedFileHandler struct { func VersionedFileHandler(doc lsp.VersionedTextDocumentIdentifier) *versionedFileHandler { return &versionedFileHandler{ fileHandler: fileHandler{uri: string(doc.URI)}, - v: doc.Version, + v: int(doc.Version), } } diff --git a/internal/lsp/hover.go b/internal/lsp/hover.go index 4e90085d3..6d6d2c8c0 100644 --- a/internal/lsp/hover.go +++ b/internal/lsp/hover.go @@ -2,25 +2,21 @@ package lsp import ( "github.com/hashicorp/hcl-lang/lang" - "github.com/hashicorp/terraform-ls/internal/mdplain" lsp "github.com/hashicorp/terraform-ls/internal/protocol" ) func HoverData(data *lang.HoverData, cc lsp.TextDocumentClientCapabilities) lsp.Hover { - mdSupported := cc.Hover != nil && - len(cc.Hover.ContentFormat) > 0 && + mdSupported := len(cc.Hover.ContentFormat) > 0 && cc.Hover.ContentFormat[0] == "markdown" - value := data.Content.Value - if data.Content.Kind == lang.MarkdownKind && !mdSupported { - value = mdplain.Clean(value) - } - - content := lsp.RawMarkedString(value) - rng := HCLRangeToLSP(data.Range) + // In theory we should be sending lsp.MarkedString (for old clients) + // when len(cc.Hover.ContentFormat) == 0, but that's not possible + // without changing lsp.Hover.Content field type to interface{} + // + // We choose to follow gopls' approach (i.e. cut off old clients). return lsp.Hover{ - Contents: []lsp.MarkedString{content}, - Range: &rng, + Contents: markupContent(data.Content, mdSupported), + Range: HCLRangeToLSP(data.Range), } } diff --git a/internal/lsp/markup_content.go b/internal/lsp/markup_content.go new file mode 100644 index 000000000..537aa28c2 --- /dev/null +++ b/internal/lsp/markup_content.go @@ -0,0 +1,25 @@ +package lsp + +import ( + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/terraform-ls/internal/mdplain" + lsp "github.com/hashicorp/terraform-ls/internal/protocol" +) + +func markupContent(content lang.MarkupContent, mdSupported bool) lsp.MarkupContent { + value := content.Value + + kind := lsp.PlainText + if content.Kind == lang.MarkdownKind { + if mdSupported { + kind = lsp.Markdown + } else { + value = mdplain.Clean(value) + } + } + + return lsp.MarkupContent{ + Kind: kind, + Value: value, + } +} diff --git a/internal/lsp/position.go b/internal/lsp/position.go index 989ad3bad..9b61b0909 100644 --- a/internal/lsp/position.go +++ b/internal/lsp/position.go @@ -40,8 +40,8 @@ func FilePositionFromDocumentPosition(params lsp.TextDocumentPositionParams, f F return &filePosition{ fh: FileHandlerFromDocumentURI(params.TextDocument.URI), pos: hcl.Pos{ - Line: params.Position.Line + 1, - Column: params.Position.Character + 1, + Line: int(params.Position.Line) + 1, + Column: int(params.Position.Character) + 1, Byte: byteOffset, }, }, nil @@ -49,7 +49,7 @@ func FilePositionFromDocumentPosition(params lsp.TextDocumentPositionParams, f F func lspPosToFsPos(pos lsp.Position) filesystem.Pos { return filesystem.Pos{ - Line: pos.Line, - Column: pos.Character, + Line: int(pos.Line), + Column: int(pos.Character), } } diff --git a/internal/lsp/range.go b/internal/lsp/range.go index 1ec4a551e..992f8fde1 100644 --- a/internal/lsp/range.go +++ b/internal/lsp/range.go @@ -13,12 +13,12 @@ func fsRangeToLSP(fsRng *filesystem.Range) lsp.Range { return lsp.Range{ Start: lsp.Position{ - Character: fsRng.Start.Column, - Line: fsRng.Start.Line, + Character: float64(fsRng.Start.Column), + Line: float64(fsRng.Start.Line), }, End: lsp.Position{ - Character: fsRng.End.Column, - Line: fsRng.End.Line, + Character: float64(fsRng.End.Column), + Line: float64(fsRng.End.Line), }, } } @@ -30,12 +30,12 @@ func lspRangeToFsRange(rng *lsp.Range) *filesystem.Range { return &filesystem.Range{ Start: filesystem.Pos{ - Line: rng.Start.Line, - Column: rng.Start.Character, + Line: int(rng.Start.Line), + Column: int(rng.Start.Character), }, End: filesystem.Pos{ - Line: rng.End.Line, - Column: rng.End.Character, + Line: int(rng.End.Line), + Column: int(rng.End.Character), }, } } @@ -43,12 +43,12 @@ func lspRangeToFsRange(rng *lsp.Range) *filesystem.Range { func HCLRangeToLSP(rng hcl.Range) lsp.Range { return lsp.Range{ Start: lsp.Position{ - Line: rng.Start.Line - 1, - Character: rng.Start.Column - 1, + Line: float64(rng.Start.Line - 1), + Character: float64(rng.Start.Column - 1), }, End: lsp.Position{ - Line: rng.End.Line - 1, - Character: rng.End.Column - 1, + Line: float64(rng.End.Line - 1), + Character: float64(rng.End.Column - 1), }, } } diff --git a/internal/lsp/symbols.go b/internal/lsp/symbols.go index b20254230..72e4a2d30 100644 --- a/internal/lsp/symbols.go +++ b/internal/lsp/symbols.go @@ -10,7 +10,7 @@ func ConvertSymbols(uri lsp.DocumentURI, sbs []decoder.Symbol) []lsp.SymbolInfor for i, s := range sbs { symbols[i] = lsp.SymbolInformation{ Name: s.Name(), - Kind: lsp.SKClass, // most applicable kind for now + Kind: lsp.Class, // most applicable kind for now Location: lsp.Location{ Range: HCLRangeToLSP(s.Range()), URI: uri, diff --git a/internal/lsp/text_edits.go b/internal/lsp/text_edits.go new file mode 100644 index 000000000..f83b43626 --- /dev/null +++ b/internal/lsp/text_edits.go @@ -0,0 +1,52 @@ +package lsp + +import ( + "github.com/hashicorp/hcl-lang/lang" + "github.com/hashicorp/terraform-ls/internal/filesystem" + lsp "github.com/hashicorp/terraform-ls/internal/protocol" +) + +func TextEditsFromDocumentChanges(changes filesystem.DocumentChanges) []lsp.TextEdit { + edits := make([]lsp.TextEdit, len(changes)) + + for i, change := range changes { + edits[i] = lsp.TextEdit{ + Range: fsRangeToLSP(change.Range()), + NewText: change.Text(), + } + } + + return edits +} + +func textEdits(tes []lang.TextEdit, snippetSupport bool) []lsp.TextEdit { + edits := make([]lsp.TextEdit, len(tes)) + + for i, te := range tes { + edits[i] = *textEdit(te, snippetSupport) + } + + return edits +} + +func textEdit(te lang.TextEdit, snippetSupport bool) *lsp.TextEdit { + if snippetSupport { + return &lsp.TextEdit{ + NewText: te.Snippet, + Range: HCLRangeToLSP(te.Range), + } + } + + return &lsp.TextEdit{ + NewText: te.NewText, + Range: HCLRangeToLSP(te.Range), + } +} + +func insertTextFormat(snippetSupport bool) lsp.InsertTextFormat { + if snippetSupport { + return lsp.SnippetTextFormat + } + + return lsp.PlainTextTextFormat +} diff --git a/langserver/handlers/cancel_request.go b/langserver/handlers/cancel_request.go index 1b1cf2d1b..375e836bf 100644 --- a/langserver/handlers/cancel_request.go +++ b/langserver/handlers/cancel_request.go @@ -2,13 +2,29 @@ package handlers import ( "context" + "fmt" "github.com/creachadair/jrpc2" lsp "github.com/hashicorp/terraform-ls/internal/protocol" ) func CancelRequest(ctx context.Context, params lsp.CancelParams) error { - id := params.ID.String() + id, err := decodeRequestID(params.ID) + if err != nil { + return err + } + jrpc2.CancelRequest(ctx, id) return nil } + +func decodeRequestID(v interface{}) (string, error) { + if val, ok := v.(string); ok { + return val, nil + } + if val, ok := v.(float64); ok { + return fmt.Sprintf("%d", int64(val)), nil + } + + return "", fmt.Errorf("unable to decode request ID: %#v", v) +} diff --git a/langserver/handlers/complete.go b/langserver/handlers/complete.go index ae71baa90..1101f0364 100644 --- a/langserver/handlers/complete.go +++ b/langserver/handlers/complete.go @@ -8,8 +8,8 @@ import ( lsp "github.com/hashicorp/terraform-ls/internal/protocol" ) -func (h *logHandler) TextDocumentComplete(ctx context.Context, params lsp.CompletionParams) (ilsp.CompletionList, error) { - var list ilsp.CompletionList +func (h *logHandler) TextDocumentComplete(ctx context.Context, params lsp.CompletionParams) (lsp.CompletionList, error) { + var list lsp.CompletionList fs, err := lsctx.DocumentStorage(ctx) if err != nil { diff --git a/langserver/handlers/did_change.go b/langserver/handlers/did_change.go index 3ee39cff4..85d510d56 100644 --- a/langserver/handlers/did_change.go +++ b/langserver/handlers/did_change.go @@ -2,7 +2,6 @@ package handlers import ( "context" - "encoding/json" "fmt" lsctx "github.com/hashicorp/terraform-ls/internal/context" @@ -10,7 +9,7 @@ import ( lsp "github.com/hashicorp/terraform-ls/internal/protocol" ) -func TextDocumentDidChange(ctx context.Context, params DidChangeTextDocumentParams) error { +func TextDocumentDidChange(ctx context.Context, params lsp.DidChangeTextDocumentParams) error { p := lsp.DidChangeTextDocumentParams{ TextDocument: lsp.VersionedTextDocumentIdentifier{ TextDocumentIdentifier: lsp.TextDocumentIdentifier{ @@ -33,11 +32,11 @@ func TextDocumentDidChange(ctx context.Context, params DidChangeTextDocumentPara } // Versions don't have to be consecutive, but they must be increasing - if p.TextDocument.Version <= f.Version() { + if int(p.TextDocument.Version) <= f.Version() { fs.CloseAndRemoveDocument(fh) return fmt.Errorf("Old version (%d) received, current version is %d. "+ "Unable to update %s. This is likely a bug, please report it.", - p.TextDocument.Version, f.Version(), p.TextDocument.URI) + int(p.TextDocument.Version), f.Version(), p.TextDocument.URI) } changes, err := ilsp.DocumentChanges(params.ContentChanges, f) @@ -72,30 +71,3 @@ func TextDocumentDidChange(ctx context.Context, params DidChangeTextDocumentPara return nil } - -// TODO: Revisit after https://github.com/hashicorp/terraform-ls/issues/118 is addressed -// Then we could switch back to upstream go-lsp -type DidChangeTextDocumentParams struct { - TextDocument VersionedTextDocumentIdentifier `json:"textDocument"` - ContentChanges []lsp.TextDocumentContentChangeEvent `json:"contentChanges"` -} - -type VersionedTextDocumentIdentifier struct { - URI lsp.DocumentURI `json:"uri"` - /** - * The version number of this document. - */ - Version int `json:"version"` -} - -// UnmarshalJSON implements non-strict json.Unmarshaler. -func (v *DidChangeTextDocumentParams) UnmarshalJSON(b []byte) error { - type t DidChangeTextDocumentParams - return json.Unmarshal(b, (*t)(v)) -} - -// UnmarshalJSON implements non-strict json.Unmarshaler. -func (v *VersionedTextDocumentIdentifier) UnmarshalJSON(b []byte) error { - type t VersionedTextDocumentIdentifier - return json.Unmarshal(b, (*t)(v)) -} diff --git a/langserver/handlers/did_open.go b/langserver/handlers/did_open.go index fa1c24f94..dacc4b228 100644 --- a/langserver/handlers/did_open.go +++ b/langserver/handlers/did_open.go @@ -86,7 +86,7 @@ func (lh *logHandler) TextDocumentDidOpen(ctx context.Context, params lsp.DidOpe err := askInitForEmptyRootModule(ctx, w, rootDir, f.Dir()) if err != nil { jrpc2.PushNotify(ctx, "window/showMessage", lsp.ShowMessageParams{ - Type: lsp.MTError, + Type: lsp.Error, Message: err.Error(), }) } @@ -101,7 +101,7 @@ func (lh *logHandler) TextDocumentDidOpen(ctx context.Context, params lsp.DidOpe readableDir, candidatePaths(rootDir, candidates[1:]), candidateDir) return jrpc2.PushNotify(ctx, "window/showMessage", lsp.ShowMessageParams{ - Type: lsp.MTWarning, + Type: lsp.Warning, Message: msg, }) } diff --git a/langserver/handlers/execute_command.go b/langserver/handlers/execute_command.go index 14c326ec4..740230454 100644 --- a/langserver/handlers/execute_command.go +++ b/langserver/handlers/execute_command.go @@ -2,6 +2,7 @@ package handlers import ( "context" + "encoding/json" "fmt" "strconv" "strings" @@ -97,14 +98,16 @@ func (c commandArgs) GetBool(variable string) (bool, bool) { return v, true } -func parseCommandArgs(arguments []interface{}) commandArgs { +func parseCommandArgs(arguments []json.RawMessage) commandArgs { args := make(map[string]interface{}) if arguments == nil { return args } for _, rawArg := range arguments { - arg, ok := rawArg.(string) - if !ok { + var arg string + err := json.Unmarshal(rawArg, &arg) + if err != nil { + // TODO: Log error continue } if arg == "" { diff --git a/langserver/handlers/formatting.go b/langserver/handlers/formatting.go index 8fc29da1c..f761a7a19 100644 --- a/langserver/handlers/formatting.go +++ b/langserver/handlers/formatting.go @@ -48,7 +48,7 @@ func (h *logHandler) TextDocumentFormatting(ctx context.Context, params lsp.Docu changes := hcl.Diff(file, original, formatted) - return ilsp.TextEdits(changes), nil + return ilsp.TextEditsFromDocumentChanges(changes), nil } func findTerraformFormatter(ctx context.Context, tff rootmodule.TerraformFormatterFinder, dir string) (exec.Formatter, error) { diff --git a/langserver/handlers/handlers_test.go b/langserver/handlers/handlers_test.go index 4b215f6ce..8fa32c0f0 100644 --- a/langserver/handlers/handlers_test.go +++ b/langserver/handlers/handlers_test.go @@ -1,7 +1,6 @@ package handlers import ( - "encoding/json" "fmt" "os" "path/filepath" @@ -18,11 +17,6 @@ import ( ) func initializeResponse(t *testing.T, commandPrefix string) string { - jsonArray, err := json.Marshal(handlers.Names(commandPrefix)) - if err != nil { - t.Fatal(err) - } - return fmt.Sprintf(`{ "jsonrpc": "2.0", "id": 1, @@ -30,18 +24,31 @@ func initializeResponse(t *testing.T, commandPrefix string) string { "capabilities": { "textDocumentSync": { "openClose": true, - "change": 2 + "change": 2, + "save": {} }, - "hoverProvider": true, "completionProvider": {}, - "documentSymbolProvider":true, - "documentFormattingProvider":true, + "hoverProvider": true, + "signatureHelpProvider": {}, + "documentSymbolProvider": true, + "codeLensProvider": {}, + "documentLinkProvider": {}, + "documentFormattingProvider": true, + "documentOnTypeFormattingProvider": { + "firstTriggerCharacter": "" + }, "executeCommandProvider": { - "commands": %s + "commands": %q + }, + "workspace": { + "workspaceFolders": {} } + }, + "serverInfo": { + "name": "" } } - }`, string(jsonArray)) + }`, handlers.Names(commandPrefix)) } func TestInitalizeAndShutdown(t *testing.T) { @@ -57,8 +64,8 @@ func TestInitalizeAndShutdown(t *testing.T) { ls.CallAndExpectResponse(t, &langserver.CallRequest{ Method: "initialize", ReqParams: fmt.Sprintf(`{ - "capabilities": {}, - "rootUri": %q, + "capabilities": {}, + "rootUri": %q, "processId": 12345 }`, tmpDir.URI())}, initializeResponse(t, "")) ls.CallAndExpectResponse(t, &langserver.CallRequest{ @@ -83,8 +90,8 @@ func TestInitalizeWithCommandPrefix(t *testing.T) { ls.CallAndExpectResponse(t, &langserver.CallRequest{ Method: "initialize", ReqParams: fmt.Sprintf(`{ - "capabilities": {}, - "rootUri": %q, + "capabilities": {}, + "rootUri": %q, "processId": 12345, "initializationOptions": { "commandPrefix": "1" @@ -106,8 +113,8 @@ func TestEOF(t *testing.T) { ls.CallAndExpectResponse(t, &langserver.CallRequest{ Method: "initialize", ReqParams: fmt.Sprintf(`{ - "capabilities": {}, - "rootUri": %q, + "capabilities": {}, + "rootUri": %q, "processId": 12345 }`, tmpDir.URI())}, initializeResponse(t, "")) diff --git a/langserver/handlers/hover_test.go b/langserver/handlers/hover_test.go index 19f6cc0f9..56bc2088f 100644 --- a/langserver/handlers/hover_test.go +++ b/langserver/handlers/hover_test.go @@ -117,9 +117,10 @@ func TestHover_withValidData(t *testing.T) { "jsonrpc": "2.0", "id": 3, "result": { - "contents": [ - "provider Block\n\nA provider block is used to specify a provider configuration" - ], + "contents": { + "kind": "plaintext", + "value": "provider Block\n\nA provider block is used to specify a provider configuration" + }, "range": { "start": { "line":0, "character":0 }, "end": { "line":0, "character":8 } diff --git a/langserver/handlers/initialize.go b/langserver/handlers/initialize.go index 8b80665a6..561a3230c 100644 --- a/langserver/handlers/initialize.go +++ b/langserver/handlers/initialize.go @@ -17,13 +17,11 @@ import ( func (lh *logHandler) Initialize(ctx context.Context, params lsp.InitializeParams) (lsp.InitializeResult, error) { serverCaps := lsp.InitializeResult{ Capabilities: lsp.ServerCapabilities{ - TextDocumentSync: &lsp.TextDocumentSyncOptionsOrKind{ - Options: &lsp.TextDocumentSyncOptions{ - OpenClose: true, - Change: lsp.TDSKIncremental, - }, + TextDocumentSync: lsp.TextDocumentSyncOptions{ + OpenClose: true, + Change: lsp.Incremental, }, - CompletionProvider: &lsp.CompletionOptions{ + CompletionProvider: lsp.CompletionOptions{ ResolveProvider: false, }, HoverProvider: true, @@ -79,13 +77,13 @@ func (lh *logHandler) Initialize(ctx context.Context, params lsp.InitializeParam // set commandPrefix for session lsctx.SetCommandPrefix(ctx, out.Options.CommandPrefix) // apply prefix to executeCommand handler names - serverCaps.Capabilities.ExecuteCommandProvider = &lsp.ExecuteCommandOptions{ + serverCaps.Capabilities.ExecuteCommandProvider = lsp.ExecuteCommandOptions{ Commands: handlers.Names(out.Options.CommandPrefix), } if len(out.UnusedKeys) > 0 { jrpc2.PushNotify(ctx, "window/showMessage", &lsp.ShowMessageParams{ - Type: lsp.MTWarning, + Type: lsp.Warning, Message: fmt.Sprintf("Unknown configuration options: %q", out.UnusedKeys), }) } @@ -98,7 +96,7 @@ func (lh *logHandler) Initialize(ctx context.Context, params lsp.InitializeParam rmPath, err := resolvePath(rootDir, rawPath) if err != nil { jrpc2.PushNotify(ctx, "window/showMessage", &lsp.ShowMessageParams{ - Type: lsp.MTWarning, + Type: lsp.Warning, Message: fmt.Sprintf("Ignoring root module path %s: %s", rawPath, err), }) continue diff --git a/langserver/handlers/initialized.go b/langserver/handlers/initialized.go index cdc571818..2307e354a 100644 --- a/langserver/handlers/initialized.go +++ b/langserver/handlers/initialized.go @@ -6,6 +6,6 @@ import ( lsp "github.com/hashicorp/terraform-ls/internal/protocol" ) -func Initialized(ctx context.Context, params lsp.None) error { +func Initialized(ctx context.Context, params lsp.InitializedParams) error { return nil } diff --git a/langserver/handlers/shutdown.go b/langserver/handlers/shutdown.go index adae7dc41..af9fbc34f 100644 --- a/langserver/handlers/shutdown.go +++ b/langserver/handlers/shutdown.go @@ -2,10 +2,8 @@ package handlers import ( "context" - - lsp "github.com/hashicorp/terraform-ls/internal/protocol" ) -func Shutdown(ctx context.Context, vs lsp.None) error { +func Shutdown(ctx context.Context, _ interface{}) error { return nil }