Skip to content

Commit

Permalink
reflect breaking changes in LSP structs
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Aug 4, 2021
1 parent 9fcca68 commit 1f2e3e8
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 35 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/completion_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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: float64(line), Character: float64(col)}
lspPos := lsp.Position{Line: uint32(line), Character: uint32(col)}

logger := logging.NewLogger(os.Stderr)

Expand Down
15 changes: 15 additions & 0 deletions internal/langserver/handlers/complete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func TestModuleCompletion_withValidData(t *testing.T) {
"items": [
{
"label": "alias",
"labelDetails": {},
"kind": 10,
"detail": "optional, string",
"documentation": "Alias for using the same provider with different configurations for different resources, e.g. eu-west",
Expand All @@ -146,6 +147,7 @@ func TestModuleCompletion_withValidData(t *testing.T) {
},
{
"label": "anonymous",
"labelDetails": {},
"kind": 10,
"detail": "optional, number",
"documentation": "Desc 1",
Expand All @@ -166,6 +168,7 @@ func TestModuleCompletion_withValidData(t *testing.T) {
},
{
"label": "base_url",
"labelDetails": {},
"kind": 10,
"detail": "optional, string",
"documentation": "Desc 2",
Expand All @@ -186,6 +189,7 @@ func TestModuleCompletion_withValidData(t *testing.T) {
},
{
"label": "individual",
"labelDetails": {},
"kind": 10,
"detail": "optional, bool",
"documentation": "Desc 3",
Expand All @@ -206,6 +210,7 @@ func TestModuleCompletion_withValidData(t *testing.T) {
},
{
"label": "version",
"labelDetails": {},
"kind": 10,
"detail": "optional, string",
"documentation": "Specifies a version constraint for the provider, e.g. ~\u003e 1.0",
Expand Down Expand Up @@ -327,6 +332,7 @@ func TestModuleCompletion_withValidDataAndSnippets(t *testing.T) {
"items": [
{
"label": "alias",
"labelDetails": {},
"kind": 10,
"detail": "optional, string",
"documentation": "Alias for using the same provider with different configurations for different resources, e.g. eu-west",
Expand All @@ -347,6 +353,7 @@ func TestModuleCompletion_withValidDataAndSnippets(t *testing.T) {
},
{
"label": "anonymous",
"labelDetails": {},
"kind": 10,
"detail": "optional, number",
"documentation": "Desc 1",
Expand All @@ -371,6 +378,7 @@ func TestModuleCompletion_withValidDataAndSnippets(t *testing.T) {
},
{
"label": "base_url",
"labelDetails": {},
"kind": 10,
"detail": "optional, string",
"documentation": "Desc 2",
Expand All @@ -395,6 +403,7 @@ func TestModuleCompletion_withValidDataAndSnippets(t *testing.T) {
},
{
"label": "individual",
"labelDetails": {},
"kind": 10,
"detail": "optional, bool",
"documentation": "Desc 3",
Expand All @@ -419,6 +428,7 @@ func TestModuleCompletion_withValidDataAndSnippets(t *testing.T) {
},
{
"label": "version",
"labelDetails": {},
"kind": 10,
"detail": "optional, string",
"documentation": "Specifies a version constraint for the provider, e.g. ~\u003e 1.0",
Expand Down Expand Up @@ -588,6 +598,7 @@ func TestVarsCompletion_withValidData(t *testing.T) {
"items": [
{
"label": "test",
"labelDetails": {},
"kind": 10,
"detail": "required, string",
"insertTextFormat":1,
Expand Down Expand Up @@ -730,6 +741,7 @@ output "test" {
"items": [
{
"label": "providers",
"labelDetails": {},
"kind": 10,
"detail": "optional, map of provider references",
"documentation": "Explicit mapping of providers which the module uses",
Expand All @@ -750,6 +762,7 @@ output "test" {
},
{
"label": "testvar",
"labelDetails": {},
"kind": 10,
"detail": "required, string",
"insertTextFormat": 1,
Expand All @@ -769,6 +782,7 @@ output "test" {
},
{
"label": "version",
"labelDetails": {},
"kind": 10,
"detail": "optional, string",
"documentation": "Constraint to set the version of the module, e.g. ~\u003e 1.0. Only applicable to modules in a module registry.",
Expand Down Expand Up @@ -809,6 +823,7 @@ output "test" {
"items": [
{
"label": "module.refname.testout",
"labelDetails": {},
"kind": 6,
"detail": "number",
"insertTextFormat": 1,
Expand Down
3 changes: 2 additions & 1 deletion internal/langserver/handlers/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func initializeResponse(t *testing.T, commandPrefix string) string {
"save": {}
},
"completionProvider": {
"triggerCharacters": [".", "["]
"triggerCharacters": [".", "["],
"completionItem":{}
},
"hoverProvider": true,
"signatureHelpProvider": {},
Expand Down
4 changes: 2 additions & 2 deletions internal/langserver/handlers/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ func (lh *logHandler) Initialize(ctx context.Context, params lsp.InitializeParam
DocumentFormattingProvider: true,
DocumentSymbolProvider: true,
WorkspaceSymbolProvider: true,
Workspace: lsp.WorkspaceGn{
WorkspaceFolders: lsp.WorkspaceFoldersGn{
Workspace: lsp.Workspace5Gn{
WorkspaceFolders: lsp.WorkspaceFolders4Gn{
Supported: true,
ChangeNotifications: "workspace/didChangeWorkspaceFolders",
},
Expand Down
2 changes: 1 addition & 1 deletion internal/langserver/handlers/workspace_symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (h *logHandler) WorkspaceSymbol(ctx context.Context, params lsp.WorkspaceSy
}

symbols = append(symbols, ilsp.SymbolInformation(mod.Path, modSymbols,
cc.Workspace.WorkspaceClientCapabilities.Symbol)...)
cc.Workspace.Symbol)...)
}

return symbols, nil
Expand Down
12 changes: 6 additions & 6 deletions internal/lsp/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ func fsRangeToLSP(fsRng *filesystem.Range) lsp.Range {

return lsp.Range{
Start: lsp.Position{
Character: float64(fsRng.Start.Column),
Line: float64(fsRng.Start.Line),
Character: uint32(fsRng.Start.Column),
Line: uint32(fsRng.Start.Line),
},
End: lsp.Position{
Character: float64(fsRng.End.Column),
Line: float64(fsRng.End.Line),
Character: uint32(fsRng.End.Column),
Line: uint32(fsRng.End.Line),
},
}
}
Expand Down Expand Up @@ -49,7 +49,7 @@ func HCLRangeToLSP(rng hcl.Range) lsp.Range {

func HCLPosToLSP(pos hcl.Pos) lsp.Position {
return lsp.Position{
Line: float64(pos.Line - 1),
Character: float64(pos.Column - 1),
Line: uint32(pos.Line - 1),
Character: uint32(pos.Column - 1),
}
}
2 changes: 1 addition & 1 deletion internal/lsp/symbols.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/zclconf/go-cty/cty"
)

func SymbolInformation(dirPath string, sbs []decoder.Symbol, caps lsp.WorkspaceSymbolClientCapabilities) []lsp.SymbolInformation {
func SymbolInformation(dirPath string, sbs []decoder.Symbol, caps *lsp.WorkspaceSymbolClientCapabilities) []lsp.SymbolInformation {
symbols := make([]lsp.SymbolInformation, len(sbs))
for i, s := range sbs {
kind, ok := symbolKind(s, caps.SymbolKind.ValueSet)
Expand Down
36 changes: 18 additions & 18 deletions internal/lsp/token_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ type TokenEncoder struct {
ClientCaps lsp.SemanticTokensClientCapabilities
}

func (te *TokenEncoder) Encode() []float64 {
data := make([]float64, 0)
func (te *TokenEncoder) Encode() []uint32 {
data := make([]uint32, 0)

for i := range te.Tokens {
data = append(data, te.encodeTokenOfIndex(i)...)
Expand All @@ -24,7 +24,7 @@ func (te *TokenEncoder) Encode() []float64 {
return data
}

func (te *TokenEncoder) encodeTokenOfIndex(i int) []float64 {
func (te *TokenEncoder) encodeTokenOfIndex(i int) []uint32 {
token := te.Tokens[i]

var tokenType TokenType
Expand Down Expand Up @@ -53,11 +53,11 @@ func (te *TokenEncoder) encodeTokenOfIndex(i int) []float64 {
tokenType = TokenTypeVariable

default:
return []float64{}
return []uint32{}
}

if !te.tokenTypeSupported(tokenType) {
return []float64{}
return []uint32{}
}

tokenTypeIdx := TokenTypesLegend(te.ClientCaps.TokenTypes).Index(tokenType)
Expand All @@ -79,7 +79,7 @@ func (te *TokenEncoder) encodeTokenOfIndex(i int) []float64 {

modifierBitMask := TokenModifiersLegend(te.ClientCaps.TokenModifiers).BitMask(modifiers)

data := make([]float64, 0)
data := make([]uint32, 0)

// Client may not support multiline tokens which would be indicated
// via lsp.SemanticTokensCapabilities.MultilineTokenSupport
Expand All @@ -104,12 +104,12 @@ func (te *TokenEncoder) encodeTokenOfIndex(i int) []float64 {
tokenLength := token.Range.End.Byte - token.Range.Start.Byte
deltaStartChar := token.Range.Start.Column - 1 - previousStartChar

data = append(data, []float64{
float64(deltaLine),
float64(deltaStartChar),
float64(tokenLength),
float64(tokenTypeIdx),
float64(modifierBitMask),
data = append(data, []uint32{
uint32(deltaLine),
uint32(deltaStartChar),
uint32(tokenLength),
uint32(tokenTypeIdx),
uint32(modifierBitMask),
}...)
} else {
// Add entry for each line of a multiline token
Expand All @@ -128,12 +128,12 @@ func (te *TokenEncoder) encodeTokenOfIndex(i int) []float64 {
length = token.Range.End.Column - 1
}

data = append(data, []float64{
float64(deltaLine),
float64(deltaStartChar),
float64(length),
float64(tokenTypeIdx),
float64(modifierBitMask),
data = append(data, []uint32{
uint32(deltaLine),
uint32(deltaStartChar),
uint32(length),
uint32(tokenTypeIdx),
uint32(modifierBitMask),
}...)

previousLine = tokenLine
Expand Down
10 changes: 5 additions & 5 deletions internal/lsp/token_encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestTokenEncoder_singleLineTokens(t *testing.T) {
},
}
data := te.Encode()
expectedData := []float64{
expectedData := []uint32{
0, 0, 7, 0, 0,
0, 8, 8, 1, 0,
1, 2, 8, 2, 0,
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestTokenEncoder_multiLineTokens(t *testing.T) {
},
}
data := te.Encode()
expectedData := []float64{
expectedData := []uint32{
1, 2, 24, 2, 0,
1, 0, 15, 2, 0,
1, 0, 11, 2, 0,
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestTokenEncoder_deltaStartCharBug(t *testing.T) {
},
}
data := te.Encode()
expectedData := []float64{
expectedData := []uint32{
0, 0, 8, 0, 0,
0, 9, 21, 1, 2,
0, 22, 20, 1, 0,
Expand Down Expand Up @@ -241,7 +241,7 @@ func TestTokenEncoder_tokenModifiers(t *testing.T) {
},
}
data := te.Encode()
expectedData := []float64{
expectedData := []uint32{
0, 0, 7, 0, 0,
0, 8, 8, 1, 1,
1, 2, 8, 2, 1,
Expand Down Expand Up @@ -324,7 +324,7 @@ func TestTokenEncoder_unsupported(t *testing.T) {
},
}
data := te.Encode()
expectedData := []float64{
expectedData := []uint32{
0, 0, 7, 0, 0,
1, 2, 8, 1, 1,
1, 2, 8, 1, 0,
Expand Down

0 comments on commit 1f2e3e8

Please sign in to comment.