update completion items
This commit is contained in:
+39
-25
@@ -14,6 +14,8 @@ import sysconfig
|
||||
import traceback
|
||||
from typing import Any, List, Optional, Sequence, Tuple
|
||||
import re
|
||||
import operator
|
||||
from functools import reduce
|
||||
|
||||
|
||||
# **********************************************************
|
||||
@@ -44,18 +46,15 @@ import lsprotocol.types as lsp
|
||||
from pygls import server, uris, workspace
|
||||
from pygls.workspace.text_document import TextDocument
|
||||
from common.load_data import standard_items
|
||||
from common.formatter import format_tcl
|
||||
from tclint.parser import Parser
|
||||
from tclint.lexer import TclSyntaxError
|
||||
from tclint.format import Formatter, FormatterOpts
|
||||
from tclint.violations import Violation
|
||||
from tools.semantic_tokens import (
|
||||
SemanticTokenCollector,
|
||||
collect_semantic_tokens,
|
||||
encode_tokens,
|
||||
)
|
||||
|
||||
from plugins.poco_plugin import commands
|
||||
from tools import checks
|
||||
from tools.semantic_tokens import _Highlighter, TOKEN_TYPES, TokenModifier
|
||||
from tools.completion_items import _Completion
|
||||
|
||||
DIAGNOSTIC_SOURCE = "nx-post-support"
|
||||
|
||||
@@ -78,7 +77,6 @@ class TclLanguageServer(server.LanguageServer):
|
||||
# parser._commands.update(commands)
|
||||
|
||||
indent = "\t" if not options.insert_spaces else " " * options.tab_size
|
||||
|
||||
formatter = Formatter(
|
||||
FormatterOpts(
|
||||
indent=indent,
|
||||
@@ -102,7 +100,7 @@ class TclLanguageServer(server.LanguageServer):
|
||||
self.parser.violations = []
|
||||
tree = self.parser.parse(document.source)
|
||||
violations += self.parser.violations
|
||||
|
||||
# log_to_output(tree.pretty(2))
|
||||
for checker in checks.get_checkers():
|
||||
violations += checker.check(document.source, tree)
|
||||
return violations
|
||||
@@ -170,16 +168,6 @@ WORKSPACE_SETTINGS = {}
|
||||
GLOBAL_SETTINGS = {}
|
||||
RUNNER = pathlib.Path(__file__).parent / "lsp_runner.py"
|
||||
|
||||
TOKEN_TYPES = [
|
||||
"command",
|
||||
"variable",
|
||||
"function",
|
||||
"string",
|
||||
"number",
|
||||
"keyword",
|
||||
"comment",
|
||||
]
|
||||
TOKEN_MODIFIERS = []
|
||||
|
||||
MAX_WORKERS = 5
|
||||
LSP_SERVER = TclLanguageServer(
|
||||
@@ -254,22 +242,48 @@ def document_diagnostic(params: lsp.DocumentDiagnosticParams):
|
||||
|
||||
@LSP_SERVER.feature(lsp.TEXT_DOCUMENT_COMPLETION)
|
||||
def on_completion(params: lsp.CompletionParams) -> list[lsp.CompletionItem]:
|
||||
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
|
||||
ci = _Completion()
|
||||
tree = LSP_SERVER.parser.parse(document.source)
|
||||
tree.accept(ci, recurse=True)
|
||||
|
||||
items = (
|
||||
standard_items.tcl_keyword_list
|
||||
+ standard_items.nx_procs
|
||||
+ standard_items.nx_variables
|
||||
+ ci.custom_functions
|
||||
)
|
||||
return lsp.CompletionList(is_incomplete=False, items=items)
|
||||
|
||||
|
||||
@LSP_SERVER.feature(lsp.TEXT_DOCUMENT_SEMANTIC_TOKENS_FULL)
|
||||
def on_semantic_tokens(params: lsp.SemanticTokensParams):
|
||||
doc = LSP_SERVER.workspace.get_document(params.text_document.uri)
|
||||
code = doc.source
|
||||
@LSP_SERVER.feature(
|
||||
lsp.TEXT_DOCUMENT_SEMANTIC_TOKENS_FULL,
|
||||
lsp.SemanticTokensLegend(
|
||||
token_types=TOKEN_TYPES,
|
||||
token_modifiers=[m.name for m in TokenModifier],
|
||||
),
|
||||
)
|
||||
def semantic_tokens(params: lsp.SemanticTokensParams):
|
||||
document = LSP_SERVER.workspace.get_text_document(params.text_document.uri)
|
||||
|
||||
tokens = collect_semantic_tokens(code)
|
||||
data = encode_tokens(tokens)
|
||||
data = []
|
||||
plugins = []
|
||||
hl = _Highlighter(plugins, log_to_output=log_to_output)
|
||||
|
||||
tree = LSP_SERVER.parser.parse(document.source)
|
||||
tree.accept(hl, recurse=True)
|
||||
|
||||
tokens = hl.tokens()
|
||||
for token in tokens:
|
||||
data.extend(
|
||||
[
|
||||
token.line,
|
||||
token.offset,
|
||||
token.lenght,
|
||||
TOKEN_TYPES.index(token.tok_type),
|
||||
reduce(operator.or_, token.tok_modifiers, 0),
|
||||
]
|
||||
)
|
||||
return lsp.SemanticTokens(data=data)
|
||||
|
||||
|
||||
@@ -401,7 +415,7 @@ def initialize(params: lsp.InitializeParams) -> lsp.InitializeResult:
|
||||
)
|
||||
semantic_tokens_legend = lsp.SemanticTokensLegend(
|
||||
token_types=TOKEN_TYPES,
|
||||
token_modifiers=TOKEN_MODIFIERS,
|
||||
token_modifiers=TokenModifier,
|
||||
)
|
||||
return lsp.InitializeResult(
|
||||
capabilities=lsp.ServerCapabilities(
|
||||
|
||||
Reference in New Issue
Block a user