-
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.
Showing
7 changed files
with
229 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package lsp | ||
|
||
import ( | ||
"fmt" | ||
idx "github.com/pherrymason/c3-lsp/lsp/indexables" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func assertSameRange(t *testing.T, expected idx.Range, actual idx.Range, msg string) { | ||
assert.Equal(t, expected.Start, actual.Start, fmt.Sprint(msg, " start")) | ||
assert.Equal(t, expected.Start, actual.Start, fmt.Sprint(msg, " end")) | ||
} | ||
|
||
func assertSameFunction(t *testing.T, expected *idx.Function, actual *idx.Function) { | ||
assert.Equal(t, expected.FunctionType(), actual.FunctionType(), expected.GetName()) | ||
assert.Equal(t, expected.GetName(), actual.GetName()) | ||
assert.Equal(t, expected.GetReturnType(), actual.GetReturnType(), expected.GetName()) | ||
assert.Equal(t, expected.ArgumentIds(), actual.ArgumentIds(), expected.GetName()) | ||
assert.Equal(t, expected.GetDocumentURI(), actual.GetDocumentURI(), expected.GetName()) | ||
|
||
assertSameRange(t, expected.GetDeclarationRange(), actual.GetDeclarationRange(), fmt.Sprint("Function declaration range:", expected.GetName())) | ||
assertSameRange(t, expected.GetDocumentRange(), actual.GetDocumentRange(), fmt.Sprint("Function document range:", expected.GetName())) | ||
|
||
assert.Equal(t, expected.GetKind(), actual.GetKind(), expected.GetName()) | ||
assert.Equal(t, expected.Variables, actual.Variables, expected.GetName()) | ||
assert.Equal(t, expected.Enums, actual.Enums, expected.GetName()) | ||
assert.Equal(t, expected.Structs, actual.Structs, expected.GetName()) | ||
|
||
assert.Equal(t, keys(expected.ChildrenFunctions), keys(actual.ChildrenFunctions)) | ||
for key, value := range expected.ChildrenFunctions { | ||
assertSameFunction(t, value, actual.ChildrenFunctions[key]) | ||
} | ||
} | ||
|
||
func createStruct(docId string, name string, members []idx.StructMember, idRange idx.Range) idx.Indexable { | ||
return idx.NewStruct( | ||
name, | ||
members, | ||
docId, | ||
idRange, | ||
) | ||
} |
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,67 @@ | ||
package indexables | ||
|
||
import protocol "github.com/tliron/glsp/protocol_3_16" | ||
|
||
type EnumBuilder struct { | ||
enum Enum | ||
} | ||
|
||
func NewEnumBuilder(name string, baseType string, docId string) *EnumBuilder { | ||
return &EnumBuilder{ | ||
enum: Enum{ | ||
name: name, | ||
baseType: baseType, | ||
BaseIndexable: BaseIndexable{ | ||
documentURI: docId, | ||
Kind: protocol.CompletionItemKindEnum, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (eb *EnumBuilder) WithIdentifierRange(lineStart uint, CharStart uint, lineEnd uint, CharEnd uint) *EnumBuilder { | ||
eb.enum.BaseIndexable.identifierRange = NewRange(lineStart, CharStart, lineEnd, CharEnd) | ||
return eb | ||
} | ||
|
||
func (eb *EnumBuilder) WithDocumentRange(lineStart uint, CharStart uint, lineEnd uint, CharEnd uint) *EnumBuilder { | ||
eb.enum.BaseIndexable.documentRange = NewRange(lineStart, CharStart, lineEnd, CharEnd) | ||
return eb | ||
} | ||
|
||
func (eb *EnumBuilder) WithEnumerator(enumerator Enumerator) *EnumBuilder { | ||
eb.enum.enumerators = append(eb.enum.enumerators, enumerator) | ||
|
||
return eb | ||
} | ||
|
||
func (eb *EnumBuilder) Build() *Enum { | ||
return &eb.enum | ||
} | ||
|
||
// EnumeratorBuilder | ||
type EnumeratorBuilder struct { | ||
enumerator Enumerator | ||
} | ||
|
||
func NewEnumeratorBuilder(name string, docId string) *EnumeratorBuilder { | ||
return &EnumeratorBuilder{ | ||
enumerator: Enumerator{ | ||
name: name, | ||
value: "", | ||
BaseIndexable: BaseIndexable{ | ||
documentURI: docId, | ||
Kind: protocol.CompletionItemKindEnumMember, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (eb *EnumeratorBuilder) WithIdentifierRange(lineStart uint, CharStart uint, lineEnd uint, CharEnd uint) *EnumeratorBuilder { | ||
eb.enumerator.BaseIndexable.identifierRange = NewRange(lineStart, CharStart, lineEnd, CharEnd) | ||
return eb | ||
} | ||
|
||
func (eb *EnumeratorBuilder) Build() Enumerator { | ||
return eb.enumerator | ||
} |
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,35 @@ | ||
package indexables | ||
|
||
import protocol "github.com/tliron/glsp/protocol_3_16" | ||
|
||
type VariableBuilder struct { | ||
variable Variable | ||
} | ||
|
||
// NewVariableBuilder | ||
func NewVariableBuilder(name string, variableType string, docId string) *VariableBuilder { | ||
return &VariableBuilder{ | ||
variable: Variable{ | ||
Name: name, | ||
Type: variableType, | ||
BaseIndexable: BaseIndexable{ | ||
documentURI: docId, | ||
Kind: protocol.CompletionItemKindVariable, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (vb *VariableBuilder) WithDocumentRange(lineStart uint, CharStart uint, lineEnd uint, CharEnd uint) *VariableBuilder { | ||
vb.variable.BaseIndexable.documentRange = NewRange(lineStart, CharStart, lineEnd, CharEnd) | ||
return vb | ||
} | ||
|
||
func (vb *VariableBuilder) WithIdentifierRange(lineStart uint, CharStart uint, lineEnd uint, CharEnd uint) *VariableBuilder { | ||
vb.variable.BaseIndexable.identifierRange = NewRange(lineStart, CharStart, lineEnd, CharEnd) | ||
return vb | ||
} | ||
|
||
func (vb *VariableBuilder) Build() Variable { | ||
return vb.variable | ||
} |
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.