Hi, and thanks for all the work on vscode and this package – much appreciated.
I maintain an extension that uses this languageservice as a foundation. A user reported a bug to me that turned out to be an issue in the way findDocumentLinks2 handles scoped NPM packages.
In this case the user maintains an SCSS library that is published in individual packages that, simplified, look like this:
@scope/package-name/
_index.scss
other.scss
package.json
They use the index to have @use statements that look like @use “@scope/package-name".
The function getModuleNameFromPath in cssNavigation doesn’t handle these paths. It always expects two forward slashes whenever there’s a scoped module. I applied a local patch to handle this case, and it seems to fix the most important problems my user was having.
function getModuleNameFromPath(path) {
- // If a scoped module (starts with @) then get up until second instance of '/', otherwise get until first instance of '/'
+ // If a scoped module (starts with @) then get up until second instance of '/', or to the end of the string for root-level imports.
if (path[0] === '@') {
- return path.substring(0, path.indexOf('/', path.indexOf('/') + 1));
+ const secondSlash = path.indexOf('/', path.indexOf('/') + 1);
+ if (secondSlash === -1) {
+ return path;
+ }
+ return path.substring(0, path.indexOf('/', path.indexOf('/') + 1));
}
- return path.substring(0, path.indexOf('/'));
+ // Otherwise get until first instance of '/'
+ return path.substring(0, path.indexOf('/'));
}
Unfortunately, Ctrl/Cmd + Click on the path in the use-statement still doesn’t work with these changes. I've tried to debug the problem, but I don't know how to hook into the openerService in vscode to solve this.
Hi, and thanks for all the work on vscode and this package – much appreciated.
I maintain an extension that uses this languageservice as a foundation. A user reported a bug to me that turned out to be an issue in the way
findDocumentLinks2handles scoped NPM packages.In this case the user maintains an SCSS library that is published in individual packages that, simplified, look like this:
They use the index to have
@usestatements that look like@use “@scope/package-name".The function getModuleNameFromPath in cssNavigation doesn’t handle these paths. It always expects two forward slashes whenever there’s a scoped module. I applied a local patch to handle this case, and it seems to fix the most important problems my user was having.
function getModuleNameFromPath(path) { - // If a scoped module (starts with @) then get up until second instance of '/', otherwise get until first instance of '/' + // If a scoped module (starts with @) then get up until second instance of '/', or to the end of the string for root-level imports. if (path[0] === '@') { - return path.substring(0, path.indexOf('/', path.indexOf('/') + 1)); + const secondSlash = path.indexOf('/', path.indexOf('/') + 1); + if (secondSlash === -1) { + return path; + } + return path.substring(0, path.indexOf('/', path.indexOf('/') + 1)); } - return path.substring(0, path.indexOf('/')); + // Otherwise get until first instance of '/' + return path.substring(0, path.indexOf('/')); }Unfortunately, Ctrl/Cmd + Click on the path in the use-statement still doesn’t work with these changes. I've tried to debug the problem, but I don't know how to hook into the
openerServiceinvscodeto solve this.