Skip to content

Commit 0f4cf27

Browse files
css: resolve bare module specifiers in @import to node_modules (#485)
Enable node_modules fallback resolution for CSS @import, matching the existing behavior in SCSS and LESS. Also fix getModuleNameFromPath to return the full path for bare specifiers without a slash (e.g. @import "bootstrap") instead of returning an empty string. Fixes microsoft/vscode#295074 Signed-off-by: Vijay Govindarajan <vijay.govindarajan91@gmail.com>
1 parent 97ab651 commit 0f4cf27

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

src/cssLanguageService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export function getCSSLanguageService(options: LanguageServiceOptions = defaultL
116116
new Parser(),
117117
new CSSCompletion(null, options, cssDataManager),
118118
new CSSHover(options && options.clientCapabilities, cssDataManager),
119-
new CSSNavigation(options && options.fileSystemProvider, false),
119+
new CSSNavigation(options && options.fileSystemProvider, true),
120120
new CSSCodeActions(cssDataManager),
121121
new CSSValidation(cssDataManager),
122122
cssDataManager

src/services/cssNavigation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ function toTwoDigitHex(n: number): string {
593593
export function getModuleNameFromPath(path: string) {
594594
const firstSlash = path.indexOf('/');
595595
if (firstSlash === -1) {
596-
return '';
596+
return path;
597597
}
598598

599599
// If a scoped module (starts with @) then get up until second instance of '/', or to the end of the string for root-level imports.

src/test/css/navigation.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,16 @@ suite('CSS - Navigation', () => {
460460
[{ range: newRange(8, 24), target: getTestResource('green/c.css') }], 'css', testUri, workspaceFolder
461461
);
462462
});
463+
464+
test('bare module specifier resolving', async function () {
465+
const ls = getCSSLS();
466+
const testUri = getTestResource('about.css');
467+
const workspaceFolder = getTestResource('');
468+
469+
await assertLinks(ls, '@import "foo/bar.css"',
470+
[{ range: newRange(8, 21), target: getTestResource('node_modules/foo/bar.css') }], 'css', testUri, workspaceFolder
471+
);
472+
});
463473
});
464474

465475
suite('Color', () => {

test/linksTestFixtures/node_modules/foo/bar.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)