Skip to content

Commit

Permalink
Update packages for map type
Browse files Browse the repository at this point in the history
  • Loading branch information
5nord committed Jan 25, 2024
1 parent 7514b69 commit d7d7e89
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/lsp/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ func isType(n syntax.Node) bool {
*syntax.EnumTypeDecl,
*syntax.PortTypeDecl,
*syntax.StructTypeDecl,
*syntax.MapTypeDecl,
*syntax.SubTypeDecl:
return true
default:
Expand Down
9 changes: 9 additions & 0 deletions internal/lsp/document_symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,15 @@ func NewAllDefinitionSymbolsFromCurrentModule(tree *ttcn3.Tree) []interface{} {
SelectionRange: setProtocolRange(begin, end),
Children: nil})
return false
case *syntax.MapTypeDecl:
if node.Name == nil {
return false
}
list = append(list, protocol.DocumentSymbol{Name: node.Name.String(), Detail: "map type", Kind: protocol.Struct,
Range: setProtocolRange(begin, end),
SelectionRange: setProtocolRange(begin, end),
Children: nil})
return false
case *syntax.BehaviourTypeDecl:
if node.Name == nil {
return false
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func getSignature(def *ttcn3.Node) string {
sig.WriteString("\n ")
sig.Write(content[node.Return.Pos():node.Return.End()])
}
case *syntax.ValueDecl, *syntax.TemplateDecl, *syntax.FormalPar, *syntax.StructTypeDecl, *syntax.ComponentTypeDecl, *syntax.EnumTypeDecl, *syntax.PortTypeDecl:
case *syntax.ValueDecl, *syntax.TemplateDecl, *syntax.FormalPar, *syntax.StructTypeDecl, *syntax.MapTypeDecl, *syntax.ComponentTypeDecl, *syntax.EnumTypeDecl, *syntax.PortTypeDecl:
sig.Write(content[def.Node.Pos()-1 : def.Node.End()])
case *syntax.Field:
if parent := def.ParentOf(node); parent != nil {
Expand Down
4 changes: 4 additions & 0 deletions internal/lsp/semantic_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const (
Enum
Interface
Struct
Map
TypeParameter
Parameter
Variable
Expand Down Expand Up @@ -51,6 +52,7 @@ var TokenTypes = []string{
Enum: "enum",
Interface: "interface",
Struct: "struct",
Map: "map",
TypeParameter: "typeParameter",
Parameter: "parameter",
Variable: "variable",
Expand Down Expand Up @@ -274,6 +276,8 @@ func DefinitionToken(tree *ttcn3.Tree, id syntax.Node) (SemanticTokenType, Seman
return Parameter, Declaration
case *syntax.StructTypeDecl:
return Struct, Definition
case *syntax.MapTypeDecl:
return Map, Definition
case *syntax.EnumTypeDecl:
if id == n.Name {
return Enum, Definition
Expand Down
20 changes: 20 additions & 0 deletions ttcn3/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,16 @@ func (p *printer) print(values ...interface{}) {
p.print(n.Fields)
p.print(unindent, n.RBrace)

case *syntax.MapSpec:
if n == nil {
return
}
p.print(n.MapTok)
p.print(n.FromTok)
p.print(n.FromType)
p.print(n.ToTok)
p.print(n.ToType)

case *syntax.ListSpec:
if n == nil {
return
Expand Down Expand Up @@ -511,6 +521,16 @@ func (p *printer) print(values ...interface{}) {
p.print(unindent, n.RBrace)
p.print(n.With)

case *syntax.MapTypeDecl:
if n == nil {
return
}
p.print(n.TypeTok)
p.print(n.Spec)
p.print(n.Name)
p.print(n.TypePars)
p.print(n.With)

case *syntax.EnumTypeDecl:
if n == nil {
return
Expand Down
6 changes: 6 additions & 0 deletions ttcn3/scopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ func NewScope(n syntax.Node, tree *Tree) *Scope {
scp.add(n)
}

case *syntax.MapTypeDecl:
scp.add(n.TypePars)

case *syntax.EnumTypeDecl:
scp.add(n.TypePars)
for _, e := range n.Enums {
Expand Down Expand Up @@ -227,6 +230,9 @@ func (scp *Scope) add(n syntax.Node) error {
case *syntax.StructTypeDecl:
scp.Insert(n, n.Name)

case *syntax.MapTypeDecl:
scp.Insert(n, n.Name)

case *syntax.EnumTypeDecl:
scp.Insert(n, n.Name)

Expand Down
2 changes: 2 additions & 0 deletions ttcn3/syntax/syntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func Name(n Node) string {
}
case *StructTypeDecl:
return Name(n.Name)
case *MapTypeDecl:
return Name(n.Name)
case *EnumTypeDecl:
return Name(n.Name)
case *BehaviourTypeDecl:
Expand Down
4 changes: 4 additions & 0 deletions ttcn3/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func (tree *Tree) Tags() []syntax.Node {
t = append(t, n)
return true

case *syntax.MapTypeDecl:
t = append(t, n)
return true

case *syntax.EnumTypeDecl:
t = append(t, n)
for _, e := range n.Enums {
Expand Down
4 changes: 3 additions & 1 deletion ttcn3/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,9 @@ func (f *finder) typeOf(def *Node) []*Node {
*syntax.PortTypeDecl,
*syntax.ListSpec,
*syntax.StructSpec,
*syntax.StructTypeDecl:
*syntax.StructTypeDecl,
*syntax.MapSpec,
*syntax.MapTypeDecl:
result = append(result, &Node{Node: n, Tree: def.Tree})
}
}
Expand Down

0 comments on commit d7d7e89

Please sign in to comment.