Skip to content

Commit

Permalink
Workaround the drive letter casing issue on windows.
Browse files Browse the repository at this point in the history
Bump from es6 to `ES2022` as is recommended in the current vscode extension template.
  • Loading branch information
raldone01 committed Dec 5, 2024
1 parent ea33181 commit 55c6e58
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
47 changes: 47 additions & 0 deletions src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,53 @@ export class ClangdContext implements vscode.Disposable {
// Do not switch to output window when clangd returns output.
revealOutputChannelOn: vscodelc.RevealOutputChannelOn.Never,

// https://github.com/clangd/vscode-clangd/issues/726
// Remove this workaround once clangd fixes the issue on their side: https://github.com/clangd/clangd/issues/108
uriConverters: {
code2Protocol: (uri: vscode.Uri): string => {
if (uri.scheme === 'file') {
function fix_windows_drive_letter_casing(uri: vscode.Uri): string | undefined {
// We can't just use process.platform === 'win32' because of remote development

// https://stackoverflow.com/a/64822303/4479969
// detect windows paths
const isWindowsPathRegex = /^(?<drive>[a-z]:)?(?<path>(?:[\\]?(?:[\w !#()-]+|[.]{1,2})+)*[\\])?(?<filename>(?:[.]?[\w !#()-]+)+)?[.]?$/i;

// Fix lower case drive letters on Windows
const fsPath = uri.fsPath

const windowsPathMatch = fsPath.match(isWindowsPathRegex);

if (!windowsPathMatch) {
// we are not dealing with a windows path
return undefined;
}

// change the drive letter to uppercase
const drive = windowsPathMatch.groups?.drive?.toUpperCase() ?? '';
const path = windowsPathMatch.groups?.path ?? '';
const filename = windowsPathMatch.groups?.filename ?? '';

if (!drive) {
// no drive letter so there is nothing to fix
return undefined;
}

// Reconstruct the path
const fixed_uri = `file:///${drive}${path}${filename}`;
return fixed_uri;
}

const fixed_uri = fix_windows_drive_letter_casing(uri);
if (fixed_uri) {
return fixed_uri;
}
}
return uri.toString();
},
protocol2Code: (uri: string) => vscode.Uri.parse(uri),
},

// We hack up the completion items a bit to prevent VSCode from re-ranking
// and throwing away all our delicious signals like type information.
//
Expand Down
12 changes: 2 additions & 10 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"target": "ES2022",
"outDir": "out",
"lib": [
"es6",
"es2015.core",
"es2015.collection",
"es2015.generator",
"es2015.iterable",
"es2015.promise",
"es2015.symbol",
"es2016.array.include",
"es2017.object"
"ES2022",
],
"sourceMap": true,
"rootDir": ".",
Expand Down

0 comments on commit 55c6e58

Please sign in to comment.