-
Notifications
You must be signed in to change notification settings - Fork 190
SCSS: resolve bare module imports on Windows (#245579) #440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
447bfa1
e427693
0df65eb
7425309
a562b11
5f2bc5a
2e618be
1d6f462
a75501c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as assert from 'assert'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please move these into scssNavigation.test.ts, where we have all other tests for node module resolving. |
||
import { getSCSSLanguageService } from '../../scssLanguageService'; | ||
import { TextDocument } from 'vscode-languageserver-textdocument'; | ||
import { DocumentContext } from '../../cssLanguageTypes'; | ||
|
||
function createDocument(contents: string, uri = 'file:///test.scss') { | ||
return TextDocument.create(uri, 'scss', 0, contents); | ||
} | ||
|
||
const dummyContext: DocumentContext = { | ||
resolveReference: (ref: string, _base: string) => ref | ||
}; | ||
|
||
const ls = getSCSSLanguageService(); | ||
|
||
async function getLinks(contents: string) { | ||
const doc = createDocument(contents); | ||
const stylesheet = ls.parseStylesheet(doc); | ||
return ls.findDocumentLinks2(doc, stylesheet, dummyContext); | ||
} | ||
|
||
describe('SCSS Navigation – scheme URL imports', () => { | ||
it('http scheme import is treated as absolute URL, not bare import', async () => { | ||
const links = await getLinks(`@import "http://example.com/foo.css";`); | ||
assert.strictEqual(links.length, 1); | ||
assert.strictEqual(links[0].target, 'http://example.com/foo.css'); | ||
}); | ||
|
||
it('https scheme import is treated as absolute URL, not bare import', async () => { | ||
const links = await getLinks(`@import "https://cdn.example.com/reset.css";`); | ||
assert.strictEqual(links.length, 1); | ||
assert.strictEqual(links[0].target, 'https://cdn.example.com/reset.css'); | ||
}); | ||
|
||
it('file scheme import is treated as absolute URL, not bare import', async () => { | ||
const links = await getLinks(`@import "file:///Users/test/project/styles/base.scss";`); | ||
assert.strictEqual(links.length, 1); | ||
assert.strictEqual(links[0].target, 'file:///Users/test/project/styles/base.scss'); | ||
}); | ||
|
||
it('custom scheme import (vscode-resource) is treated as absolute URL, not bare import', async () => { | ||
const links = await getLinks(`@import "vscode-resource://file/some.css";`); | ||
assert.strictEqual(links.length, 1); | ||
assert.strictEqual(links[0].target, 'vscode-resource://file/some.css'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { assert } from 'chai'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please move these into scssNavigation.test.ts, where we have all other tests for node module resolving. |
||
import { getSCSSLanguageService } from '../../cssLanguageService'; | ||
import { TextDocument } from 'vscode-languageserver-textdocument'; | ||
import { FileType, getNodeFSRequestService } from '../../nodeFs'; | ||
import { URI } from 'vscode-uri'; | ||
|
||
const ls = getSCSSLanguageService(); | ||
const mockFS = getNodeFSRequestService(); | ||
|
||
describe('SCSS link navigation – node_modules', () => { | ||
it('resolves bootstrap path on Windows', async () => { | ||
const doc = TextDocument.create('file:///c:/proj/app.scss', 'scss', 1, | ||
"@import 'bootstrap/scss/variables';"); | ||
const links = await ls.findDocumentLinks2(doc, ls.parseStylesheet(doc), {}, mockFS); | ||
const expected = URI.file('c:/proj/node_modules/bootstrap/scss/_variables.scss').toString(); | ||
assert.strictEqual(links[0].target, expected); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node module resolving should only happen when
this.resolveModuleReferences
is true.(only set for LESS and SCSS).
So this needs to go behind the
if (this.resolveModuleReferences) {
.I looks like we already call
resolveModuleReference
there, so this code is not necessary?