-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
238 additions
and
56 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,23 +1,60 @@ | ||
package completion | ||
|
||
import ( | ||
"github.com/opa-oz/go-todo/todo" | ||
"github.com/opa-oz/pug-lsp/pkg/documents" | ||
"github.com/opa-oz/pug-lsp/pkg/query" | ||
protocol "github.com/tliron/glsp/protocol_3_16" | ||
) | ||
|
||
func MixinsCompletion(_ *CompletionMetaParams, completionItems []protocol.CompletionItem) *[]protocol.CompletionItem { | ||
valueKind := protocol.CompletionItemKindValue | ||
func docMixins(doc *documents.Document, completionItems []protocol.CompletionItem, exclude string) *[]protocol.CompletionItem { | ||
functionKind := protocol.CompletionItemKindFunction | ||
|
||
todo.T("Grab mixins from lined files and offer") | ||
defaultSymbol := "mixins" | ||
defaultToInsert := "mixins." | ||
for _, def := range doc.Mixins { | ||
insert := def.Name | ||
if insert == exclude { | ||
continue | ||
} | ||
|
||
completionItems = append(completionItems, protocol.CompletionItem{ | ||
Label: todo.String("Look for mixins", "Default mixin - [Mixin]"), | ||
Kind: &valueKind, | ||
Detail: &defaultSymbol, | ||
InsertText: &defaultToInsert, | ||
}) | ||
if len(*def.Arguments) > 0 { | ||
insert += "()" | ||
} | ||
|
||
completionItems = append(completionItems, protocol.CompletionItem{ | ||
Label: def.Name, | ||
Kind: &functionKind, | ||
Detail: &def.Definition, | ||
InsertText: &insert, | ||
}) | ||
} | ||
|
||
return &completionItems | ||
} | ||
|
||
func MixinsCompletion(meta *CompletionMetaParams, completionItems []protocol.CompletionItem) *[]protocol.CompletionItem { | ||
hasMixinDefAncestor := query.HasMixinDefinitionAncestor(meta.CurrentNode) | ||
var excludeMixin string | ||
|
||
if hasMixinDefAncestor { | ||
mixinDef := query.FindUpwards(meta.CurrentNode, query.MixinDefinitionNode, -1) | ||
if mixinDef != nil { | ||
mixinName := query.FindDownwards(mixinDef, query.MixinNameNode, 2) | ||
if mixinName != nil { | ||
excludeMixin = (*meta.Doc.Content)[mixinName.StartByte():mixinName.EndByte()] | ||
} | ||
} | ||
} | ||
|
||
completionItems = *docMixins(meta.Doc, completionItems, excludeMixin) | ||
for _, include := range meta.Doc.Includes { | ||
doc, ok := meta.DocumentStore.Get(*include.URI) | ||
|
||
if !ok { | ||
(*meta.Logger).Println("Something shady with include", include.Path) | ||
continue | ||
} | ||
|
||
completionItems = *docMixins(doc, completionItems, excludeMixin) | ||
} | ||
|
||
return &completionItems | ||
} |
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
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
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,45 @@ | ||
package lsp | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/opa-oz/pug-lsp/pkg/query" | ||
sitter "github.com/smacker/go-tree-sitter" | ||
) | ||
|
||
type Mixin struct { | ||
Source string | ||
Name string | ||
Definition string | ||
Arguments *[]string | ||
} | ||
|
||
func NewMixin(source string, node *sitter.Node, content *string) *Mixin { | ||
nameNode := query.FindDownwards(node, query.MixinNameNode, 2) | ||
|
||
if nameNode == nil { | ||
return nil | ||
} | ||
|
||
definition := (*content)[nameNode.StartByte():nameNode.EndByte()] | ||
mixinAttributes := query.FindDownwards(node, query.MixinAttributesNode, 2) | ||
var arguments []string | ||
|
||
if mixinAttributes != nil { | ||
attributesRanges, err := query.FindAll(mixinAttributes, query.AttributeNamesQ) | ||
if err == nil { | ||
for _, rng := range *attributesRanges { | ||
arguments = append(arguments, strings.Trim((*content)[rng.StartPos:rng.EndPos], "")) | ||
} | ||
|
||
definition += (*content)[mixinAttributes.StartByte():mixinAttributes.EndByte()] | ||
} | ||
} | ||
|
||
return &Mixin{ | ||
Source: source, | ||
Name: (*content)[nameNode.StartByte():nameNode.EndByte()], | ||
Arguments: &arguments, | ||
Definition: definition, | ||
} | ||
} |
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
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.