Skip to content

Commit 59bfeb1

Browse files
committed
Simplify the regex expression.
1 parent 55c6e58 commit 59bfeb1

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/clangd-context.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,8 @@ export class ClangdContext implements vscode.Disposable {
108108
function fix_windows_drive_letter_casing(uri: vscode.Uri): string | undefined {
109109
// We can't just use process.platform === 'win32' because of remote development
110110

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

115114
// Fix lower case drive letters on Windows
116115
const fsPath = uri.fsPath
@@ -123,17 +122,16 @@ export class ClangdContext implements vscode.Disposable {
123122
}
124123

125124
// 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 ?? '';
125+
const drive_letter = windowsPathMatch.groups?.drive_letter?.toUpperCase() ?? '';
126+
const remainingPath = windowsPathMatch.groups?.remainingPath ?? '';
129127

130-
if (!drive) {
128+
if (!drive_letter) {
131129
// no drive letter so there is nothing to fix
132130
return undefined;
133131
}
134132

135133
// Reconstruct the path
136-
const fixed_uri = `file:///${drive}${path}${filename}`;
134+
const fixed_uri = `file:///${drive_letter}:\\${remainingPath}`;
137135
return fixed_uri;
138136
}
139137

0 commit comments

Comments
 (0)