diff --git a/library/src/main/kotlin/com/strumenta/kolasu/languageserver/library/KolasuServer.kt b/library/src/main/kotlin/com/strumenta/kolasu/languageserver/library/KolasuServer.kt index 9778d98..3211904 100644 --- a/library/src/main/kotlin/com/strumenta/kolasu/languageserver/library/KolasuServer.kt +++ b/library/src/main/kotlin/com/strumenta/kolasu/languageserver/library/KolasuServer.kt @@ -12,6 +12,7 @@ import com.strumenta.kolasu.traversing.findByPosition import com.strumenta.kolasu.traversing.walk import org.eclipse.lsp4j.DefinitionParams import org.eclipse.lsp4j.Diagnostic +import org.eclipse.lsp4j.DiagnosticSeverity import org.eclipse.lsp4j.DidChangeConfigurationParams import org.eclipse.lsp4j.DidChangeTextDocumentParams import org.eclipse.lsp4j.DidChangeWatchedFilesParams @@ -106,9 +107,27 @@ open class KolasuServer(private val parser: ASTParser, private val params?.apply { assert(this.contentChanges.size == 1) parseAndPublishDiagnostics(this.contentChanges.first().text, params.textDocument.uri) + showLeaves(params) } } + private fun showLeaves(params: DidChangeTextDocumentParams) { + val uri = params.textDocument.uri + val tree = uriToParsingResult[uri]?.root ?: return + + val diagnostics = mutableListOf() + for (node in tree.walk()) { + if (node.children.isEmpty() || node.position == null) continue + if (tree.findByPosition(node.position!!) != node) { + val diagnostic = Diagnostic(toLSPRange(node.position!!), "Leaf type: ${node.simpleNodeType} but findByPositionType: ${tree.findByPosition(node.position!!)?.simpleNodeType}") + diagnostic.severity = DiagnosticSeverity.Warning + diagnostics.add(diagnostic) + } + } + + client.publishDiagnostics(PublishDiagnosticsParams(params.textDocument.uri, diagnostics)) + } + private fun parseAndPublishDiagnostics(text: String, uri: String) { val parsingResult = parser.parse(text) parsingResult.root?.let {