add tcl parser

This commit is contained in:
2025-07-18 22:49:49 +02:00
parent e2ba07c8b4
commit e045e1533c
3 changed files with 63 additions and 59 deletions
+15 -12
View File
@@ -13,6 +13,7 @@ import sys
import sysconfig
import traceback
from typing import Any, Optional, Sequence
from parser.parser import parse_tcl, format_tree
# **********************************************************
@@ -179,18 +180,20 @@ def _get_severity(*_codes: list[str]) -> lsp.DiagnosticSeverity:
@LSP_SERVER.feature(lsp.TEXT_DOCUMENT_FORMATTING)
def formatting(params: lsp.DocumentFormattingParams) -> list[lsp.TextEdit] | None:
"""LSP handler for textDocument/formatting request."""
# If your tool is a formatter you can use this handler to provide
# formatting support on save. You have to return an array of lsp.TextEdit
# objects, to provide your formatted results.
document = LSP_SERVER.workspace.get_document(params.text_document.uri)
edits = _formatting_helper(document)
if edits:
return edits
# NOTE: If you provide [] array, VS Code will clear the file of all contents.
# To indicate no changes to file return None.
return None
text = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
tree, _ = parse_tcl(text)
if not tree:
return []
new_text = format_tree(tree)
return [
{
"range": {
"start": {"line": 0, "character": 0},
"end": {"line": len(text.splitlines()), "character": 0},
},
"newText": new_text,
}
]
def _formatting_helper(document: workspace.Document) -> list[lsp.TextEdit] | None: