load all files for completion
This commit is contained in:
@@ -50,6 +50,7 @@ from tools.semantic_tokens import _Highlighter, TOKEN_TYPES, TokenModifier
|
||||
from tools.completion_items import completion
|
||||
from tools.inlay_hint import InlayHintGenerator
|
||||
|
||||
|
||||
DIAGNOSTIC_SOURCE = "nx-post-support"
|
||||
|
||||
|
||||
@@ -190,8 +191,16 @@ def did_open(params: lsp.DidOpenTextDocumentParams) -> None:
|
||||
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
|
||||
LSP_SERVER.compute_diagnostics(document)
|
||||
completion.reset()
|
||||
tree = LSP_SERVER.parser.parse(document.source)
|
||||
tree.accept(completion, recurse=True)
|
||||
all_tcl_files = get_all_tcl_files(LSP_SERVER.workspace.root_path)
|
||||
|
||||
for filepath in all_tcl_files:
|
||||
try:
|
||||
with open(filepath, "r", encoding="utf-8") as f:
|
||||
source = f.read()
|
||||
tree = LSP_SERVER.parser.parse(source)
|
||||
tree.accept(completion, recurse=True)
|
||||
except Exception as e:
|
||||
log_to_output(f"Fehler beim Parsen von {filepath}: {e}")
|
||||
|
||||
|
||||
@LSP_SERVER.feature(lsp.TEXT_DOCUMENT_DID_SAVE)
|
||||
@@ -205,14 +214,24 @@ def did_close(params: lsp.DidCloseTextDocumentParams) -> None:
|
||||
"""LSP handler for textDocument/didClose request."""
|
||||
|
||||
|
||||
def get_all_tcl_files(root_path: str) -> list[str]:
|
||||
"""Sammelt alle .tcl-Dateien rekursiv im gegebenen Verzeichnis"""
|
||||
tcl_files = []
|
||||
for dirpath, _, filenames in os.walk(root_path):
|
||||
for filename in filenames:
|
||||
if filename.endswith(".tcl"):
|
||||
tcl_files.append(os.path.join(dirpath, filename))
|
||||
return tcl_files
|
||||
|
||||
|
||||
@LSP_SERVER.feature(lsp.TEXT_DOCUMENT_DID_CHANGE)
|
||||
def did_change(params: lsp.DidChangeTextDocumentParams) -> None:
|
||||
"""LSP handler for textDocument/didChange request"""
|
||||
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
|
||||
LSP_SERVER.compute_diagnostics(document)
|
||||
completion.reset()
|
||||
tree = LSP_SERVER.parser.parse(document.source)
|
||||
tree.accept(completion, recurse=True)
|
||||
# completion.reset()
|
||||
# tree = LSP_SERVER.parser.parse(document.source)
|
||||
# tree.accept(completion, recurse=True)
|
||||
|
||||
|
||||
@LSP_SERVER.feature(
|
||||
@@ -256,7 +275,10 @@ def on_completion(params: lsp.CompletionParams) -> list[lsp.CompletionItem]:
|
||||
# @LSP_SERVER.feature(lsp.TEXT_DOCUMENT_DOCUMENT_SYMBOL)
|
||||
# def document_symbols(params: lsp.DocumentSymbolParams):
|
||||
# doc = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
|
||||
# return []
|
||||
# ast = LSP_SERVER.parser.parse(doc.source)
|
||||
# symbols = LSP_SERVER.extract_tcl_symbols(ast)
|
||||
|
||||
# return symbols
|
||||
|
||||
|
||||
@LSP_SERVER.feature(lsp.TEXT_DOCUMENT_INLAY_HINT)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import xml.etree.ElementTree as ET
|
||||
from dataclasses import dataclass
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
@dataclass
|
||||
class SourcedFiles:
|
||||
layer_name: str
|
||||
subfolder: Optional[str]
|
||||
files: List[str]
|
||||
|
||||
|
||||
def read_psc_file(psc_file: str) -> List[SourcedFiles]:
|
||||
tree = ET.parse(psc_file)
|
||||
root = tree.getroot()
|
||||
|
||||
layers = root.findall(".//Layer")
|
||||
|
||||
layer_info_list: List[SourcedFiles] = []
|
||||
for layer in layers:
|
||||
layer_name = layer.attrib.get("Name")
|
||||
subfolder = layer.attrib.get("SubFolder")
|
||||
# Scripts-Filenames
|
||||
scripts = layer.find("Scripts")
|
||||
script_names = []
|
||||
if scripts is not None:
|
||||
for filename in scripts.findall("Filename"):
|
||||
name = filename.attrib.get("Name")
|
||||
if name:
|
||||
script_names.append(name)
|
||||
|
||||
layer_info_list.append(
|
||||
SourcedFiles(layer_name=layer_name, subfolder=subfolder, files=script_names)
|
||||
)
|
||||
return layer_info_list
|
||||
Reference in New Issue
Block a user