read all procs from psc file
This commit is contained in:
+31
-18
@@ -49,7 +49,7 @@ from tools import checks, parser
|
|||||||
from tools.semantic_tokens import _Highlighter, TOKEN_TYPES, TokenModifier
|
from tools.semantic_tokens import _Highlighter, TOKEN_TYPES, TokenModifier
|
||||||
from tools.completion_items import completion
|
from tools.completion_items import completion
|
||||||
from tools.inlay_hint import InlayHintGenerator
|
from tools.inlay_hint import InlayHintGenerator
|
||||||
|
from tools.file_sourcing import get_all_psc_files, read_psc_file, SourcedFile
|
||||||
|
|
||||||
DIAGNOSTIC_SOURCE = "nx-post-support"
|
DIAGNOSTIC_SOURCE = "nx-post-support"
|
||||||
|
|
||||||
@@ -61,6 +61,7 @@ class TclLanguageServer(server.LanguageServer):
|
|||||||
for command in commands:
|
for command in commands:
|
||||||
self.parser._commands.update(command)
|
self.parser._commands.update(command)
|
||||||
self.diagnostics = {}
|
self.diagnostics = {}
|
||||||
|
self.poco_completion: dict = {}
|
||||||
|
|
||||||
def format(
|
def format(
|
||||||
self,
|
self,
|
||||||
@@ -190,17 +191,6 @@ def did_open(params: lsp.DidOpenTextDocumentParams) -> None:
|
|||||||
"""LSP handler for textDocument/didOpen request."""
|
"""LSP handler for textDocument/didOpen request."""
|
||||||
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
|
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
|
||||||
LSP_SERVER.compute_diagnostics(document)
|
LSP_SERVER.compute_diagnostics(document)
|
||||||
completion.reset()
|
|
||||||
# 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)
|
@LSP_SERVER.feature(lsp.TEXT_DOCUMENT_DID_SAVE)
|
||||||
@@ -219,9 +209,6 @@ def did_change(params: lsp.DidChangeTextDocumentParams) -> None:
|
|||||||
"""LSP handler for textDocument/didChange request"""
|
"""LSP handler for textDocument/didChange request"""
|
||||||
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
|
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
|
||||||
LSP_SERVER.compute_diagnostics(document)
|
LSP_SERVER.compute_diagnostics(document)
|
||||||
# completion.reset()
|
|
||||||
# tree = LSP_SERVER.parser.parse(document.source)
|
|
||||||
# tree.accept(completion, recurse=True)
|
|
||||||
|
|
||||||
|
|
||||||
@LSP_SERVER.feature(
|
@LSP_SERVER.feature(
|
||||||
@@ -252,12 +239,15 @@ def document_diagnostic(params: lsp.DocumentDiagnosticParams):
|
|||||||
@LSP_SERVER.feature(lsp.TEXT_DOCUMENT_COMPLETION)
|
@LSP_SERVER.feature(lsp.TEXT_DOCUMENT_COMPLETION)
|
||||||
def on_completion(params: lsp.CompletionParams) -> list[lsp.CompletionItem]:
|
def on_completion(params: lsp.CompletionParams) -> list[lsp.CompletionItem]:
|
||||||
_ = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
|
_ = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
|
||||||
|
poco = []
|
||||||
|
|
||||||
|
for key, value in LSP_SERVER.poco_completion.items():
|
||||||
|
poco.extend(value)
|
||||||
items = (
|
items = (
|
||||||
standard_items.tcl_keyword_list
|
standard_items.tcl_keyword_list
|
||||||
+ standard_items.nx_procs
|
+ standard_items.nx_procs
|
||||||
+ standard_items.nx_variables
|
+ standard_items.nx_variables
|
||||||
+ completion.custom_functions
|
+ poco
|
||||||
)
|
)
|
||||||
return lsp.CompletionList(is_incomplete=False, items=items)
|
return lsp.CompletionList(is_incomplete=False, items=items)
|
||||||
|
|
||||||
@@ -455,8 +445,31 @@ def initialize(params: lsp.InitializeParams) -> lsp.InitializeResult:
|
|||||||
|
|
||||||
|
|
||||||
@LSP_SERVER.feature(lsp.INITIALIZED)
|
@LSP_SERVER.feature(lsp.INITIALIZED)
|
||||||
def initialized(params: lsp.InitializedParams) -> lsp.InitializeResult:
|
def initialized(params: lsp.InitializedParams):
|
||||||
pass
|
root = LSP_SERVER.workspace.root_path
|
||||||
|
psc_files = get_all_psc_files(pathlib.Path(root))
|
||||||
|
for psc_file in psc_files:
|
||||||
|
poco_files = read_psc_file(psc_file)
|
||||||
|
for sourced_layer in poco_files:
|
||||||
|
completion.reset()
|
||||||
|
try:
|
||||||
|
file_root = pathlib.Path(root).joinpath(
|
||||||
|
sourced_layer.subfolder if sourced_layer.subfolder else ""
|
||||||
|
)
|
||||||
|
for tcl_file in sourced_layer.files:
|
||||||
|
filepath = pathlib.Path(file_root).joinpath(f"{tcl_file}.tcl")
|
||||||
|
if not filepath.exists():
|
||||||
|
continue
|
||||||
|
completion.reset()
|
||||||
|
source = filepath.read_text(encoding="utf-8")
|
||||||
|
tree = LSP_SERVER.parser.parse(source)
|
||||||
|
tree.accept(completion, recurse=True)
|
||||||
|
|
||||||
|
LSP_SERVER.poco_completion[str(filepath)] = (
|
||||||
|
completion.custom_functions
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
log_to_output(f"Fehler beim Parsen von {filepath}: {e}")
|
||||||
|
|
||||||
|
|
||||||
@LSP_SERVER.feature(lsp.EXIT)
|
@LSP_SERVER.feature(lsp.EXIT)
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ def read_psc_file(psc_file: Path) -> List[SourcedFile]:
|
|||||||
|
|
||||||
|
|
||||||
def get_all_psc_files(root_path: Path) -> list[Path]:
|
def get_all_psc_files(root_path: Path) -> list[Path]:
|
||||||
"""Sammelt alle .tcl-Dateien rekursiv im gegebenen Verzeichnis"""
|
|
||||||
return [path for path in root_path.rglob("*.psc")]
|
return [path for path in root_path.rglob("*.psc")]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user