Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix for hover and navigation #114

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
- `Select Environment` actions now update the run environment instead of base.
- Modified status bar to show both environments, i.e.`base + local`, and `base` is no longer selectable.
- Fixed a minor bug where status bar showing incorrect text, i.e. it shows `prod` insteadf of `base + prod`.
- Fixed a bug where namespace dataset navigation is not working properly
- Fixed a bug where navigating on nested parameters should go to the top level key.

# 0.1.0
- Expanded pipeline discovery to support `*pipeline*.py` patterns and improved handling of nested subdirectories.
Expand Down
41 changes: 26 additions & 15 deletions bundled/tool/lsp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
)
from pygls.server import LanguageServer


class KedroLanguageServer(LanguageServer):
"""Store Kedro-specific information in the language server."""

Expand Down Expand Up @@ -197,9 +198,7 @@ def _get_conf_paths(server: KedroLanguageServer, key):
config_loader: OmegaConfigLoader = server.config_loader
patterns = config_loader.config_patterns.get(key, [])
# By default is local
run_env = str(
Path(config_loader.conf_source) / server.run_env
)
run_env = str(Path(config_loader.conf_source) / server.run_env)
base_env = str(Path(config_loader.conf_source) / config_loader.base_env)

# Extract from OmegaConfigLoader source code
Expand All @@ -216,16 +215,23 @@ def _get_conf_paths(server: KedroLanguageServer, key):
):
if not config_loader._is_hidden(each):
tmp_paths.append(Path(each))
paths = paths + list(set(tmp_paths))

# Reuse OmegaConfigLoader logic as much as possible so we don't need to write our tests here
deduplicated_paths = set(tmp_paths)
valid_config_paths = [
path
for path in deduplicated_paths
if config_loader._is_valid_config_path(path)
]
paths = paths + list(valid_config_paths)
return paths


def _get_param_location(
server: KedroLanguageServer, word: str
) -> Optional[Location]:
def _get_param_location(server: KedroLanguageServer, word: str) -> Optional[Location]:
words = word.split("params:")
if len(words) > 1:
param = words[0] # Top key
words = words[1].split(".") # ["params:", "a.b.c"]
param = words[0] # Top level key ["a","b","c"]
else:
return None
log_to_output(f"Attempt to search `{param}` from parameters file")
Expand Down Expand Up @@ -284,7 +290,7 @@ def _query_parameter(document, word=None):

def _query_catalog(document, word=None):
if not word:
word = document.word_at_position(params.position)
word = document.word_at_position(params.position, RE_START_WORD, RE_END_WORD)
catalog_paths = _get_conf_paths(server, "catalog")
log_for_lsp_debug(f"Attempt to search `{word}` from catalog")
log_for_lsp_debug(f"{catalog_paths=}")
Expand Down Expand Up @@ -325,7 +331,7 @@ def _query_catalog(document, word=None):
# If no result, return current location
# This is a VSCode specific logic called Alternative Definition Command
# By default, it triggers Go to Reference so it supports using mouse click for both directions
# from pipline to config and config to pipeline
# from pipeline to config and config to pipeline
uri = params.text_document.uri
pos = params.position
curr_pos = Position(line=pos.line, character=pos.character)
Expand Down Expand Up @@ -533,11 +539,15 @@ def log_for_lsp_debug(msg: str):


def _is_pipeline(uri):
from pathlib import Path

filename = Path(uri).name
path = Path(uri)
filename = path.name
if "pipeline" in str(filename):
return True
# Inside pipelines folder
if (
"pipelines" in path.parts
): # [file:, Users, dummy, pipelines, pipeline_name, file.py]
return True
return False


Expand All @@ -552,10 +562,10 @@ def definition_from_flowchart(ls, word):
result = definition(LSP_SERVER, params=None, word=word)
return result


@LSP_SERVER.command("kedro.getProjectData")
def get_project_data_from_viz(lsClient):
"""Get project data from kedro viz
"""
"""Get project data from kedro viz"""
from kedro_viz.server import load_and_populate_data
from kedro_viz.api.rest.responses import get_kedro_project_json_data

Expand All @@ -570,6 +580,7 @@ def get_project_data_from_viz(lsClient):
print("Execution completed.")
return data


### End of kedro-lsp


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Kedro",
"displayName": "Kedro",
"description": "A Kedro VSCode Extension.",
"version": "0.2.0-rc0",
"version": "0.2.0-rc1",
"preview": false,
"serverInfo": {
"name": "Kedro",
Expand Down