Skip to content

Commit

Permalink
feat: handle workspace config event (#91)
Browse files Browse the repository at this point in the history
* feat: handle workspace config event

* Fix linter errors

---------

Co-authored-by: Regen <regen100@users.noreply.github.com>
  • Loading branch information
heywhy and regen100 authored Apr 20, 2024
1 parent 9529df5 commit 890bb77
Show file tree
Hide file tree
Showing 3 changed files with 294 additions and 315 deletions.
26 changes: 23 additions & 3 deletions cmake_language_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
TEXT_DOCUMENT_DID_SAVE,
TEXT_DOCUMENT_FORMATTING,
TEXT_DOCUMENT_HOVER,
WORKSPACE_DID_CHANGE_CONFIGURATION,
CompletionItem,
CompletionItemKind,
CompletionList,
CompletionOptions,
CompletionParams,
CompletionTriggerKind,
DidChangeConfigurationParams,
DocumentFormattingParams,
Hover,
InitializeParams,
Expand Down Expand Up @@ -46,15 +48,33 @@ def __init__(self, *args: Any) -> None:

@self.feature(INITIALIZE)
def initialize(params: InitializeParams) -> None:
opts = params.initialization_options
opts = params.initialization_options or {}

cmake = getattr(opts, "cmakeExecutable", "cmake")
builddir = getattr(opts, "buildDirectory", "")
cmake = opts.get("cmakeExecutable", "cmake")
builddir = opts.get("buildDirectory", "")
logging.info(f"cmakeExecutable={cmake}, buildDirectory={builddir}")

self._api = API(cmake, Path(builddir))
self._api.parse_doc()

@self.feature(WORKSPACE_DID_CHANGE_CONFIGURATION)
def workspace_did_change_configuration(
params: DidChangeConfigurationParams,
) -> None:
settings = params.settings or {}
assert self._api is not None
if opts := settings.get("initialization_options"):
cmake = opts.get("cmakeExecutable", self._api._cmake)
builddir = opts.get("buildDirectory", self._api._build.as_posix())
logging.info(f"cmakeExecutable={cmake}, buildDirectory={builddir}")

api = API(cmake, Path(builddir))
api.parse_doc()

self._api = api

run_cmake()

trigger_characters = ["{", "("]

@self.feature(
Expand Down
Loading

0 comments on commit 890bb77

Please sign in to comment.