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

Workaround the drive letter casing issue on windows. #747

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
45 changes: 45 additions & 0 deletions src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,51 @@ 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

// detect windows paths
const isWindowsPathRegex = /^(?<drive_letter>[a-zA-Z]):[\\\/](?<remainingPath>.*)/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_letter = windowsPathMatch.groups?.drive_letter?.toUpperCase() ?? '';
const remainingPath = windowsPathMatch.groups?.remainingPath ?? '';

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

// Reconstruct the path
const fixed_uri = `file:///${drive_letter}:\\${remainingPath}`;
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