Skip to content

Commit

Permalink
Fix for ${fileDirname} crash (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig committed Nov 8, 2023
1 parent 87c6469 commit b4c4735
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
17 changes: 15 additions & 2 deletions bundled/tool/lsp_server.py
Expand Up @@ -368,6 +368,19 @@ def _get_settings_by_document(document: workspace.Document | None):
# *****************************************************
# Internal execution APIs.
# *****************************************************
def get_cwd(settings: Dict[str, Any], document: Optional[workspace.Document]) -> str:
"""Returns cwd for the given settings and document."""
if settings["cwd"] == "${workspaceFolder}":
return settings["workspaceFS"]

if settings["cwd"] == "${fileDirname}":
if document is not None:
return os.fspath(pathlib.Path(document.path).parent)
return settings["workspaceFS"]

return settings["cwd"]


# pylint: disable=too-many-branches
def _run_tool_on_document(
document: workspace.Document,
Expand All @@ -393,7 +406,7 @@ def _run_tool_on_document(
settings = copy.deepcopy(_get_settings_by_document(document))

code_workspace = settings["workspaceFS"]
cwd = settings["cwd"]
cwd = get_cwd(settings, document)

use_path = False
use_rpc = False
Expand Down Expand Up @@ -476,7 +489,7 @@ def _run_tool_on_document(
def _run_tool(extra_args: Sequence[str], settings: Dict[str, Any]) -> utils.RunResult:
"""Runs tool."""
code_workspace = settings["workspaceFS"]
cwd = settings["cwd"]
cwd = get_cwd(settings, None)

use_path = False
use_rpc = False
Expand Down
4 changes: 2 additions & 2 deletions src/common/server.ts
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import * as fsapi from 'fs-extra';
import { Disposable, env, l10n, LanguageStatusSeverity, LogOutputChannel, WorkspaceFolder } from 'vscode';
import { Disposable, env, l10n, LanguageStatusSeverity, LogOutputChannel, Uri, WorkspaceFolder } from 'vscode';
import { State } from 'vscode-languageclient';
import {
LanguageClient,
Expand All @@ -28,7 +28,7 @@ async function createServer(
initializationOptions: IInitOptions,
): Promise<LanguageClient> {
const command = settings.interpreter[0];
const cwd = settings.cwd;
const cwd = settings.cwd === '${fileDirname}' ? Uri.parse(settings.workspace).fsPath : settings.cwd;

// Set debugger path needed for debugging python code.
const newEnv = { ...process.env };
Expand Down

0 comments on commit b4c4735

Please sign in to comment.