-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop protocol.Position in favour of storing protocol.Range for Variab…
…les and Functions. Include (WIP) return type for functions. Refactored indexed structure to have scope information, this allows to disambiguate between symbols with same names, and discard symbols that should be hidden in some contexts. Hover feature is improved. Index simple enums.
- Loading branch information
1 parent
976a0a7
commit 9f70f16
Showing
15 changed files
with
850 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package lsp | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestWordInIndex(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
expected string | ||
position int | ||
}{ | ||
{"start of doc", "hello", 1}, | ||
{"word", "expected", 14}, | ||
{"word with underscore", "bye_bye", 24}, | ||
} | ||
|
||
source := "hello this is expected bye_bye" | ||
doc := NewDocumentFromString("x", source) | ||
for _, tt := range cases { | ||
t.Run(tt.name, func(t *testing.T) { | ||
word, _ := doc.WordInIndex(tt.position) | ||
|
||
assert.Equal(t, tt.expected, word) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package indexables | ||
|
||
import protocol "github.com/tliron/glsp/protocol_3_16" | ||
|
||
type Enumerator struct { | ||
name string | ||
value string | ||
BaseIndexable | ||
} | ||
|
||
func NewEnumerator(name string, value string, identifierPosition protocol.Range) Enumerator { | ||
return Enumerator{ | ||
name: name, | ||
value: value, | ||
BaseIndexable: BaseIndexable{ | ||
identifierRange: identifierPosition, | ||
Kind: protocol.CompletionItemKindEnumMember, | ||
}, | ||
} | ||
} | ||
|
||
type Enum struct { | ||
name string | ||
baseType string | ||
enumerators []Enumerator | ||
BaseIndexable | ||
} | ||
|
||
func NewEnum(name string, baseType string, enumerators []Enumerator, identifierRangePosition protocol.Range, documentRangePosition protocol.Range) Enum { | ||
return Enum{ | ||
name: name, | ||
baseType: baseType, | ||
enumerators: enumerators, | ||
BaseIndexable: BaseIndexable{ | ||
identifierRange: identifierRangePosition, | ||
documentRange: documentRangePosition, | ||
Kind: protocol.CompletionItemKindEnum, | ||
}, | ||
} | ||
} | ||
|
||
func (e Enum) GetName() string { | ||
return e.name | ||
} | ||
|
||
func (e Enum) GetKind() protocol.CompletionItemKind { | ||
return e.Kind | ||
} | ||
|
||
func (e Enum) GetDocumentURI() protocol.DocumentUri { | ||
return e.documentURI | ||
} | ||
|
||
func (e Enum) GetDeclarationRange() protocol.Range { | ||
return e.documentRange | ||
} | ||
|
||
func (e Enum) GetDocumentRange() protocol.Range { | ||
return e.identifierRange | ||
} | ||
|
||
func (e *Enum) AddEnumerators(enumerators []Enumerator) { | ||
e.enumerators = enumerators | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package indexables | ||
|
||
import "github.com/tliron/glsp/protocol_3_16" | ||
|
||
type Indexable interface { | ||
GetName() string | ||
GetKind() protocol.CompletionItemKind | ||
GetDocumentURI() protocol.DocumentUri | ||
GetDeclarationRange() protocol.Range | ||
GetDocumentRange() protocol.Range | ||
} | ||
|
||
type IndexableCollection []Indexable | ||
|
||
type BaseIndexable struct { | ||
documentURI protocol.DocumentUri | ||
identifierRange protocol.Range | ||
documentRange protocol.Range | ||
Kind protocol.CompletionItemKind | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.