-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from samtkit/semantic-tokens
Implement "Semantic Tokens", "Go to declaration" and "Find references"
Showing
25 changed files
with
1,587 additions
and
440 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
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
52 changes: 52 additions & 0 deletions
52
language-server/src/main/kotlin/tools/samt/ls/SamtDeclarationLookup.kt
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,52 @@ | ||
package tools.samt.ls | ||
|
||
import tools.samt.common.Location | ||
import tools.samt.parser.BundleIdentifierNode | ||
import tools.samt.parser.ExpressionNode | ||
import tools.samt.parser.FileNode | ||
import tools.samt.parser.IdentifierNode | ||
import tools.samt.semantic.* | ||
|
||
class SamtDeclarationLookup private constructor() : SamtSemanticLookup<Location, UserDeclared>() { | ||
override fun markType(node: ExpressionNode, type: Type) { | ||
super.markType(node, type) | ||
|
||
if (type is UserDeclared) { | ||
if (node is BundleIdentifierNode) { | ||
this[node.components.last().location] = type | ||
} else { | ||
this[node.location] = type | ||
} | ||
} | ||
} | ||
|
||
override fun markOperationReference(operation: ServiceType.Operation, reference: IdentifierNode) { | ||
super.markOperationReference(operation, reference) | ||
this[reference.location] = operation | ||
} | ||
|
||
override fun markProviderDeclaration(providerType: ProviderType) { | ||
super.markProviderDeclaration(providerType) | ||
this[providerType.declaration.name.location] = providerType | ||
} | ||
|
||
override fun markServiceDeclaration(serviceType: ServiceType) { | ||
super.markServiceDeclaration(serviceType) | ||
this[serviceType.declaration.name.location] = serviceType | ||
} | ||
|
||
override fun markRecordDeclaration(recordType: RecordType) { | ||
super.markRecordDeclaration(recordType) | ||
this[recordType.declaration.name.location] = recordType | ||
} | ||
|
||
override fun markOperationDeclaration(operation: ServiceType.Operation) { | ||
super.markOperationDeclaration(operation) | ||
this[operation.declaration.name.location] = operation | ||
} | ||
|
||
companion object { | ||
fun analyze(fileNode: FileNode, samtPackage: Package) = | ||
SamtDeclarationLookup().also { it.analyze(fileNode, samtPackage) } | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
language-server/src/main/kotlin/tools/samt/ls/SamtReferencesLookup.kt
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,47 @@ | ||
package tools.samt.ls | ||
|
||
import tools.samt.common.Location | ||
import tools.samt.parser.BundleIdentifierNode | ||
import tools.samt.parser.ExpressionNode | ||
import tools.samt.parser.FileNode | ||
import tools.samt.parser.IdentifierNode | ||
import tools.samt.semantic.Package | ||
import tools.samt.semantic.ServiceType | ||
import tools.samt.semantic.Type | ||
import tools.samt.semantic.UserDeclared | ||
|
||
class SamtReferencesLookup private constructor() : SamtSemanticLookup<UserDeclared, List<Location>>() { | ||
private fun addUsage(declaration: UserDeclared, usage: Location) { | ||
if (this[declaration] == null) { | ||
this[declaration] = mutableListOf() | ||
} | ||
(this[declaration] as MutableList<Location>) += usage | ||
} | ||
|
||
override fun markType(node: ExpressionNode, type: Type) { | ||
super.markType(node, type) | ||
|
||
if (type is UserDeclared) { | ||
if (node is BundleIdentifierNode) { | ||
addUsage(type, node.components.last().location) | ||
} else { | ||
addUsage(type, node.location) | ||
} | ||
} | ||
} | ||
|
||
override fun markOperationReference(operation: ServiceType.Operation, reference: IdentifierNode) { | ||
super.markOperationReference(operation, reference) | ||
addUsage(operation, reference.location) | ||
} | ||
|
||
companion object { | ||
fun analyze(filesAndPackages: List<Pair<FileNode, Package>>): SamtReferencesLookup { | ||
val lookup = SamtReferencesLookup() | ||
for ((fileInfo, samtPackage) in filesAndPackages) { | ||
lookup.analyze(fileInfo, samtPackage) | ||
} | ||
return lookup | ||
} | ||
} | ||
} |
Oops, something went wrong.