Skip to content

Commit 13bbb65

Browse files
committed
Fix resolve tildes in file paths
We forgot to handle the VSCode side of path resolution Fixes #707
1 parent a085f8f commit 13bbb65

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1818
- Fixed inlay hint off-by-one on a function definition with an explicit self (i.e., `function Class.foo(self, param)`) ([#702](https://github.com/JohnnyMorganz/luau-lsp/issues/702))
1919
- Fixed `:GetPropertyChangedSignal()` still showing children in autocomplete for DataModel types ([#699](https://github.com/JohnnyMorganz/luau-lsp/issues/699))
2020
- Fixed grandparent's children showing up in autocomplete of FindFirstChild
21+
- Fixed tilde expansion (`~`) for paths to home directory not working in VSCode ([#707](https://github.com/JohnnyMorganz/luau-lsp/issues/707))
2122

2223
## [1.32.0] - 2024-07-14
2324

editors/code/src/extension.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ const startLanguageServer = async (context: vscode.ExtensionContext) => {
7676
// Load extra type definitions
7777
const definitionFiles = typesConfig.get<string[]>("definitionFiles");
7878
if (definitionFiles) {
79-
for (const definitionPath of definitionFiles) {
79+
for (let definitionPath of definitionFiles) {
80+
definitionPath = utils.resolvePath(definitionPath);
8081
let uri;
8182
if (vscode.workspace.workspaceFolders) {
8283
uri = utils.resolveUri(
@@ -99,7 +100,8 @@ const startLanguageServer = async (context: vscode.ExtensionContext) => {
99100
// Load extra documentation files
100101
const documentationFiles = typesConfig.get<string[]>("documentationFiles");
101102
if (documentationFiles) {
102-
for (const documentationPath of documentationFiles) {
103+
for (let documentationPath of documentationFiles) {
104+
documentationPath = utils.resolvePath(documentationPath);
103105
let uri;
104106
if (vscode.workspace.workspaceFolders) {
105107
uri = utils.resolveUri(
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as assert from "assert";
2+
import path from "path";
3+
import os from "os";
4+
import { resolvePath } from "../../utils";
5+
6+
suite("Utils Test Suite", () => {
7+
test("Expands tilde to home directory (directory sep: /)", () => {
8+
assert.strictEqual(
9+
path.join(os.homedir(), "typedefs.luau"),
10+
resolvePath("~/typedefs.luau"),
11+
);
12+
});
13+
14+
test("Expands tilde to home directory (directory sep: \\)", () => {
15+
assert.strictEqual(
16+
path.join(os.homedir(), "typedefs.luau"),
17+
resolvePath("~\\typedefs.luau"),
18+
);
19+
});
20+
});

editors/code/src/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode";
22
import * as path from "path";
3+
import * as os from "os";
34

45
export const basenameUri = (uri: vscode.Uri): string => {
56
return path.basename(uri.fsPath);
@@ -15,3 +16,11 @@ export const exists = (uri: vscode.Uri): Thenable<boolean> => {
1516
export const resolveUri = (uri: vscode.Uri, ...paths: string[]): vscode.Uri => {
1617
return vscode.Uri.file(path.resolve(uri.fsPath, ...paths));
1718
};
19+
20+
/// Expand ~ at the start of the path
21+
export const resolvePath = (mainPath: string): string => {
22+
if (mainPath.startsWith("~/") || mainPath.startsWith("~\\")) {
23+
return path.join(os.homedir(), mainPath.slice(2));
24+
}
25+
return mainPath;
26+
};

0 commit comments

Comments
 (0)