Skip to content

Commit 55c6e58

Browse files
committed
Workaround the drive letter casing issue on windows.
Bump from es6 to `ES2022` as is recommended in the current vscode extension template.
1 parent ea33181 commit 55c6e58

File tree

2 files changed

+49
-10
lines changed

2 files changed

+49
-10
lines changed

src/clangd-context.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,53 @@ export class ClangdContext implements vscode.Disposable {
100100
// Do not switch to output window when clangd returns output.
101101
revealOutputChannelOn: vscodelc.RevealOutputChannelOn.Never,
102102

103+
// https://github.com/clangd/vscode-clangd/issues/726
104+
// Remove this workaround once clangd fixes the issue on their side: https://github.com/clangd/clangd/issues/108
105+
uriConverters: {
106+
code2Protocol: (uri: vscode.Uri): string => {
107+
if (uri.scheme === 'file') {
108+
function fix_windows_drive_letter_casing(uri: vscode.Uri): string | undefined {
109+
// We can't just use process.platform === 'win32' because of remote development
110+
111+
// https://stackoverflow.com/a/64822303/4479969
112+
// detect windows paths
113+
const isWindowsPathRegex = /^(?<drive>[a-z]:)?(?<path>(?:[\\]?(?:[\w !#()-]+|[.]{1,2})+)*[\\])?(?<filename>(?:[.]?[\w !#()-]+)+)?[.]?$/i;
114+
115+
// Fix lower case drive letters on Windows
116+
const fsPath = uri.fsPath
117+
118+
const windowsPathMatch = fsPath.match(isWindowsPathRegex);
119+
120+
if (!windowsPathMatch) {
121+
// we are not dealing with a windows path
122+
return undefined;
123+
}
124+
125+
// change the drive letter to uppercase
126+
const drive = windowsPathMatch.groups?.drive?.toUpperCase() ?? '';
127+
const path = windowsPathMatch.groups?.path ?? '';
128+
const filename = windowsPathMatch.groups?.filename ?? '';
129+
130+
if (!drive) {
131+
// no drive letter so there is nothing to fix
132+
return undefined;
133+
}
134+
135+
// Reconstruct the path
136+
const fixed_uri = `file:///${drive}${path}${filename}`;
137+
return fixed_uri;
138+
}
139+
140+
const fixed_uri = fix_windows_drive_letter_casing(uri);
141+
if (fixed_uri) {
142+
return fixed_uri;
143+
}
144+
}
145+
return uri.toString();
146+
},
147+
protocol2Code: (uri: string) => vscode.Uri.parse(uri),
148+
},
149+
103150
// We hack up the completion items a bit to prevent VSCode from re-ranking
104151
// and throwing away all our delicious signals like type information.
105152
//

tsconfig.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
11
{
22
"compilerOptions": {
33
"module": "commonjs",
4-
"target": "es6",
4+
"target": "ES2022",
55
"outDir": "out",
66
"lib": [
7-
"es6",
8-
"es2015.core",
9-
"es2015.collection",
10-
"es2015.generator",
11-
"es2015.iterable",
12-
"es2015.promise",
13-
"es2015.symbol",
14-
"es2016.array.include",
15-
"es2017.object"
7+
"ES2022",
168
],
179
"sourceMap": true,
1810
"rootDir": ".",

0 commit comments

Comments
 (0)