Skip to content

Commit

Permalink
Simplify the regex expression.
Browse files Browse the repository at this point in the history
  • Loading branch information
raldone01 committed Dec 5, 2024
1 parent 55c6e58 commit ef96d20
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/clangd-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ export class ClangdContext implements vscode.Disposable {
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;
const isWindowsPathRegex = /^(?<drive_letter>[a-zA-Z]):[\\\/](?<remainingPath>.*)/i;

// Fix lower case drive letters on Windows
const fsPath = uri.fsPath
Expand All @@ -124,16 +123,15 @@ export class ClangdContext implements vscode.Disposable {

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

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

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

Expand Down

0 comments on commit ef96d20

Please sign in to comment.