Open KagaJiankui opened 2 years ago
This bug can be resolved by adding toString()
in the erroneous functions listed below:
export function normalizePath(p: string, opt: PathNormalizationOptions): string {
const normCase: NormalizationSetting = opt ? opt.normCase ? opt.normCase : 'never' : 'never';
const normUnicode: NormalizationSetting = opt ? opt.normUnicode ? opt.normUnicode : 'never' : 'never';
let norm = path.normalize(p.toString()); // p->p.toString()
while (path.sep !== path.posix.sep && norm.includes(path.sep)) {
norm = norm.replace(path.sep, path.posix.sep);
}
//...
}
export function replaceAll(str: string, needle: string, what: string) {
const pattern = escapeStringForRegex(needle);
const re = new RegExp(pattern, 'g');
return str.toString().replace(re, what); //str.replace()->str.toString().replace()
}
export function escapeStringForRegex(str: string): string {
return str.toString().replace(/([.*+?^=!:${}()|\[\]\/\\])/g, '\\$1'); //str.replace()->str.toString().replace()
}
export function fixPaths(str: string | undefined) {
if (str === undefined) {
return undefined;
}
const fix_paths = /[A-Z]:(\\((?![<>:\"\/\\|\?\*]).)+)*\\?(?!\\)/gi;
let pathmatch: RegExpMatchArray | null = null;
let newstr = str;
while ((pathmatch = fix_paths.exec(str))) {
const pathfull = pathmatch[0];
const fixslash = pathfull.replace(/\\/g, '/');
newstr = newstr.toString().replace(pathfull, fixslash); //str.replace()->str.toString().replace()
}
return newstr;
}
I think there's a bigger problem here if the parameters typed as "string" are not actually "strings". We'll need to try to reproduce this error under a debugger and see what the problem is.
This problem pops up only on the WSL version of VSCode so far, and there is no problem on Windows version temporarily.
By casting the parameters passed into the suspicious functions into string can also resolve the problem temporarily on WSL2 version of the VSCode.
Hmm, can't reproduce the problem on my WSL2 instance running Ubuntu 22.04.
Brief Issue Summary
The CMake Tools extension on the VSCode on WSL cannot run at all due to the error
TypeError: str.replace is not a function
.Reproduce the bug
cmake-tools v1.9.2
extension.CMake Tools Diagnostics
The CMake: Log Diagnostics cannot run at all since the extension can't load.
Debug Log
There isn't debug log since the extension cannot load due to the error trace.
Installed Extensions and Activated Extensions