Working
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/marte-community/marte-dev-tools/internal/formatter"
|
"github.com/marte-community/marte-dev-tools/internal/formatter"
|
||||||
@@ -575,8 +576,16 @@ func handleCompletion(params CompletionParams) *CompletionList {
|
|||||||
|
|
||||||
// Case 1: Assigning a value (Ends with "=" or "= ")
|
// Case 1: Assigning a value (Ends with "=" or "= ")
|
||||||
if strings.Contains(prefix, "=") {
|
if strings.Contains(prefix, "=") {
|
||||||
parts := strings.Split(prefix, "=")
|
lastIdx := strings.LastIndex(prefix, "=")
|
||||||
key := strings.TrimSpace(parts[len(parts)-2])
|
beforeEqual := prefix[:lastIdx]
|
||||||
|
|
||||||
|
// Find the last identifier before '='
|
||||||
|
key := ""
|
||||||
|
re := regexp.MustCompile(`[a-zA-Z][a-zA-Z0-9_\-]*`)
|
||||||
|
matches := re.FindAllString(beforeEqual, -1)
|
||||||
|
if len(matches) > 0 {
|
||||||
|
key = matches[len(matches)-1]
|
||||||
|
}
|
||||||
|
|
||||||
if key == "Class" {
|
if key == "Class" {
|
||||||
return suggestClasses()
|
return suggestClasses()
|
||||||
@@ -584,7 +593,7 @@ func handleCompletion(params CompletionParams) *CompletionList {
|
|||||||
|
|
||||||
container := tree.GetNodeContaining(path, parser.Position{Line: params.Position.Line + 1, Column: col + 1})
|
container := tree.GetNodeContaining(path, parser.Position{Line: params.Position.Line + 1, Column: col + 1})
|
||||||
if container != nil {
|
if container != nil {
|
||||||
return suggestFieldValues(container, key)
|
return suggestFieldValues(container, key, path)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -700,19 +709,31 @@ func suggestFields(container *index.ProjectNode) *CompletionList {
|
|||||||
return &CompletionList{Items: items}
|
return &CompletionList{Items: items}
|
||||||
}
|
}
|
||||||
|
|
||||||
func suggestFieldValues(container *index.ProjectNode, field string) *CompletionList {
|
func suggestFieldValues(container *index.ProjectNode, field string, path string) *CompletionList {
|
||||||
|
var root *index.ProjectNode
|
||||||
|
if iso, ok := tree.IsolatedFiles[path]; ok {
|
||||||
|
root = iso
|
||||||
|
} else {
|
||||||
|
root = tree.Root
|
||||||
|
}
|
||||||
|
|
||||||
if field == "DataSource" {
|
if field == "DataSource" {
|
||||||
return suggestObjects("DataSource")
|
return suggestObjects(root, "DataSource")
|
||||||
}
|
}
|
||||||
if field == "Functions" {
|
if field == "Functions" {
|
||||||
return suggestObjects("GAM")
|
return suggestObjects(root, "GAM")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func suggestObjects(filter string) *CompletionList {
|
func suggestObjects(root *index.ProjectNode, filter string) *CompletionList {
|
||||||
|
if root == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
var items []CompletionItem
|
var items []CompletionItem
|
||||||
tree.Walk(func(node *index.ProjectNode) {
|
|
||||||
|
var walk func(*index.ProjectNode)
|
||||||
|
walk = func(node *index.ProjectNode) {
|
||||||
match := false
|
match := false
|
||||||
if filter == "GAM" {
|
if filter == "GAM" {
|
||||||
if isGAM(node) {
|
if isGAM(node) {
|
||||||
@@ -731,7 +752,13 @@ func suggestObjects(filter string) *CompletionList {
|
|||||||
Detail: node.Metadata["Class"],
|
Detail: node.Metadata["Class"],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
for _, child := range node.Children {
|
||||||
|
walk(child)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
walk(root)
|
||||||
return &CompletionList{Items: items}
|
return &CompletionList{Items: items}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -207,6 +207,7 @@ func (p *Parser) parseSubnode() (Subnode, bool) {
|
|||||||
}
|
}
|
||||||
if t.Type == TokenEOF {
|
if t.Type == TokenEOF {
|
||||||
p.addError(t.Position, "unexpected EOF, expected }")
|
p.addError(t.Position, "unexpected EOF, expected }")
|
||||||
|
sub.EndPosition = t.Position
|
||||||
return sub, false
|
return sub, false
|
||||||
}
|
}
|
||||||
def, ok := p.parseDefinition()
|
def, ok := p.parseDefinition()
|
||||||
|
|||||||
Reference in New Issue
Block a user