kolasu icon indicating copy to clipboard operation
kolasu copied to clipboard

Support for code completion in the scope provider API

Open loradd opened this issue 1 year ago • 1 comments

Code completion requests could be answered using the scoping rules defined through a language-specific scope provider. In order to enable such feature, ScopeDescription must support searching for all symbols names - possibly filtered through a text string. I suggest adding the following method to ScopeDescription:

fun allVisibleNames(filter: String = ""): Sequence<String> = sequence<String>{
    // include names from all local nodes in this scope
    namesToLocalSymbolNodes.keys.filter { it.contains(filter) }.forEach { yield(it) }
    // include names from all external symbols in this scope 
    namesToExternalSymbolIdentifiers.keys.filter { it.contains(filter) }.forEach { yield(it) }
    // include all visible names from the parent scope (if any)
    parent?.allVisibleNames(filter)?.also { yieldAll(it) }
}

Furthermore, the ScopeProvider should provide support to retrieve scopes from string property names and node types, e.g. scopeFor(nodeType: String, propertyName: String): ScopeDescription?. In this way, we would need to retrieve Node instances before asking for the scope of a given reference - which would be cumbersome in the language server and require some sort of node repository access before. This feature would enable computing scopes from information contained in SymbolDescriptions.

loradd avatar Mar 12 '24 23:03 loradd

This may be useful indeed

ftomassetti avatar Mar 13 '24 12:03 ftomassetti