diff --git a/src/test/css/navigation.test.ts b/src/test/css/navigation.test.ts index c9c89680..406ce573 100644 --- a/src/test/css/navigation.test.ts +++ b/src/test/css/navigation.test.ts @@ -12,7 +12,7 @@ import { colorFrom256RGB, colorFromHSL, colorFromHWB } from '../../languageFacts import { TextDocument, DocumentHighlightKind, Range, Position, TextEdit, Color, - ColorInformation, DocumentLink, SymbolKind, SymbolInformation, Location, LanguageService, Stylesheet, getCSSLanguageService, DocumentSymbol, + ColorInformation, DocumentLink, SymbolKind, SymbolInformation, Location, LanguageService, Stylesheet, getCSSLanguageService, DocumentSymbol, LanguageSettings, } from '../../cssLanguageService'; import { URI } from 'vscode-uri'; @@ -184,6 +184,17 @@ function getCSSLS() { return getCSSLanguageService({ fileSystemProvider: getFsProvider() }); } +function aliasSettings(): LanguageSettings { + return { + "alias": { + "paths": { + "@SingleStylesheet": "/src/assets/styles.css", + "@AssetsDir/*": "/src/assets/*", + } + } + }; +} + suite('CSS - Navigation', () => { suite('Scope', () => { @@ -364,6 +375,16 @@ suite('CSS - Navigation', () => { ]); }); + test('aliased @import links', async function () { + const settings = aliasSettings(); + const ls = getCSSLS(); + ls.configure(settings); + + await assertLinks(ls, '@import "@SingleStylesheet"', [{ range: newRange(8, 27), target: "test://test/src/assets/styles.css"}]); + + await assertLinks(ls, '@import "@AssetsDir/styles.css"', [{ range: newRange(8, 31), target: "test://test/src/assets/styles.css"}]); + }); + test('links in rulesets', async () => { const ls = getCSSLS(); await assertLinks(ls, `body { background-image: url(./foo.jpg)`, [ diff --git a/src/test/scss/scssNavigation.test.ts b/src/test/scss/scssNavigation.test.ts index 08540261..45f66fef 100644 --- a/src/test/scss/scssNavigation.test.ts +++ b/src/test/scss/scssNavigation.test.ts @@ -6,10 +6,10 @@ import * as nodes from '../../parser/cssNodes'; import { assertSymbolsInScope, assertScopesAndSymbols, assertHighlights, assertColorSymbols, assertLinks, newRange, getTestResource, assertDocumentSymbols } from '../css/navigation.test'; -import { getSCSSLanguageService, DocumentLink, TextDocument, SymbolKind } from '../../cssLanguageService'; +import { getSCSSLanguageService, DocumentLink, TextDocument, SymbolKind, LanguageSettings } from '../../cssLanguageService'; import * as assert from 'assert'; import * as path from 'path'; -import { URI, Utils } from 'vscode-uri'; +import { URI } from 'vscode-uri'; import { getFsProvider } from '../testUtil/fsProvider'; import { getDocumentContext } from '../testUtil/documentContext'; @@ -17,8 +17,24 @@ function getSCSSLS() { return getSCSSLanguageService({ fileSystemProvider: getFsProvider() }); } -async function assertDynamicLinks(docUri: string, input: string, expected: DocumentLink[]) { +function aliasSettings(): LanguageSettings { + return { + "alias": { + "paths": { + "@SassStylesheet": "/src/assets/styles.scss", + "@NoUnderscoreDir/*": "/noUnderscore/*", + "@UnderscoreDir/*": "/underscore/*", + "@BothDir/*": "/both/*", + } + } + }; +} + +async function assertDynamicLinks(docUri: string, input: string, expected: DocumentLink[], settings?: LanguageSettings) { const ls = getSCSSLS(); + if (settings) { + ls.configure(settings); + } const document = TextDocument.create(docUri, 'scss', 0, input); const stylesheet = ls.parseStylesheet(document); @@ -177,6 +193,35 @@ suite('SCSS - Navigation', () => { }); + test('SCSS aliased links', async function () { + const fixtureRoot = path.resolve(__dirname, '../../../../src/test/scss/linkFixture'); + const getDocumentUri = (relativePath: string) => { + return URI.file(path.resolve(fixtureRoot, relativePath)).toString(true); + }; + + const settings = aliasSettings(); + const ls = getSCSSLS(); + ls.configure(settings); + + await assertLinks(ls, '@import "@SassStylesheet"', [{ range: newRange(8, 25), target: "test://test/src/assets/styles.scss"}]); + + await assertDynamicLinks(getDocumentUri('./'), `@import '@NoUnderscoreDir/foo'`, [ + { range: newRange(8, 30), target: getDocumentUri('./noUnderscore/foo.scss') } + ], settings); + + await assertDynamicLinks(getDocumentUri('./'), `@import '@UnderscoreDir/foo'`, [ + { range: newRange(8, 28), target: getDocumentUri('./underscore/_foo.scss') } + ], settings); + + await assertDynamicLinks(getDocumentUri('./'), `@import '@BothDir/foo'`, [ + { range: newRange(8, 22), target: getDocumentUri('./both/foo.scss') } + ], settings); + + await assertDynamicLinks(getDocumentUri('./'), `@import '@BothDir/_foo'`, [ + { range: newRange(8, 23), target: getDocumentUri('./both/_foo.scss') } + ], settings); + }); + test('SCSS module file links', async () => { const fixtureRoot = path.resolve(__dirname, '../../../../src/test/scss/linkFixture/module'); const getDocumentUri = (relativePath: string) => {