Skip to content

Commit ef96d20

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

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/clangd-context.ts

Lines changed: 3 additions & 5 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
@@ -124,16 +123,15 @@ export class ClangdContext implements vscode.Disposable {
124123

125124
// change the drive letter to uppercase
126125
const drive = windowsPathMatch.groups?.drive?.toUpperCase() ?? '';
127-
const path = windowsPathMatch.groups?.path ?? '';
128-
const filename = windowsPathMatch.groups?.filename ?? '';
126+
const remainingPath = windowsPathMatch.groups?.remainingPath ?? '';
129127

130128
if (!drive) {
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}${remainingPath}`;
137135
return fixed_uri;
138136
}
139137

0 commit comments

Comments
 (0)