|
6 | 6 |
|
7 | 7 | import * as nodes from '../../parser/cssNodes';
|
8 | 8 | import { assertSymbolsInScope, assertScopesAndSymbols, assertHighlights, assertColorSymbols, assertLinks, newRange, getTestResource, assertDocumentSymbols } from '../css/navigation.test';
|
9 |
| -import { getSCSSLanguageService, DocumentLink, TextDocument, SymbolKind } from '../../cssLanguageService'; |
| 9 | +import { getSCSSLanguageService, DocumentLink, TextDocument, SymbolKind, LanguageSettings } from '../../cssLanguageService'; |
10 | 10 | import * as assert from 'assert';
|
11 | 11 | import * as path from 'path';
|
12 |
| -import { URI, Utils } from 'vscode-uri'; |
| 12 | +import { URI } from 'vscode-uri'; |
13 | 13 | import { getFsProvider } from '../testUtil/fsProvider';
|
14 | 14 | import { getDocumentContext } from '../testUtil/documentContext';
|
15 | 15 |
|
16 | 16 | function getSCSSLS() {
|
17 | 17 | return getSCSSLanguageService({ fileSystemProvider: getFsProvider() });
|
18 | 18 | }
|
19 | 19 |
|
20 |
| -async function assertDynamicLinks(docUri: string, input: string, expected: DocumentLink[]) { |
| 20 | +function aliasSettings(): LanguageSettings { |
| 21 | + return { |
| 22 | + "alias": { |
| 23 | + "paths": { |
| 24 | + "@SassStylesheet": "/src/assets/styles.scss", |
| 25 | + "@NoUnderscoreDir/*": "/noUnderscore/*", |
| 26 | + "@UnderscoreDir/*": "/underscore/*", |
| 27 | + "@BothDir/*": "/both/*", |
| 28 | + } |
| 29 | + } |
| 30 | + }; |
| 31 | +} |
| 32 | + |
| 33 | +async function assertDynamicLinks(docUri: string, input: string, expected: DocumentLink[], settings?: LanguageSettings) { |
21 | 34 | const ls = getSCSSLS();
|
| 35 | + if (settings) { |
| 36 | + ls.configure(settings); |
| 37 | + } |
22 | 38 | const document = TextDocument.create(docUri, 'scss', 0, input);
|
23 | 39 |
|
24 | 40 | const stylesheet = ls.parseStylesheet(document);
|
@@ -177,6 +193,35 @@ suite('SCSS - Navigation', () => {
|
177 | 193 |
|
178 | 194 | });
|
179 | 195 |
|
| 196 | + test('SCSS aliased links', async function () { |
| 197 | + const fixtureRoot = path.resolve(__dirname, '../../../../src/test/scss/linkFixture'); |
| 198 | + const getDocumentUri = (relativePath: string) => { |
| 199 | + return URI.file(path.resolve(fixtureRoot, relativePath)).toString(true); |
| 200 | + }; |
| 201 | + |
| 202 | + const settings = aliasSettings(); |
| 203 | + const ls = getSCSSLS(); |
| 204 | + ls.configure(settings); |
| 205 | + |
| 206 | + await assertLinks(ls, '@import "@SassStylesheet"', [{ range: newRange(8, 25), target: "test://test/src/assets/styles.scss"}]); |
| 207 | + |
| 208 | + await assertDynamicLinks(getDocumentUri('./'), `@import '@NoUnderscoreDir/foo'`, [ |
| 209 | + { range: newRange(8, 30), target: getDocumentUri('./noUnderscore/foo.scss') } |
| 210 | + ], settings); |
| 211 | + |
| 212 | + await assertDynamicLinks(getDocumentUri('./'), `@import '@UnderscoreDir/foo'`, [ |
| 213 | + { range: newRange(8, 28), target: getDocumentUri('./underscore/_foo.scss') } |
| 214 | + ], settings); |
| 215 | + |
| 216 | + await assertDynamicLinks(getDocumentUri('./'), `@import '@BothDir/foo'`, [ |
| 217 | + { range: newRange(8, 22), target: getDocumentUri('./both/foo.scss') } |
| 218 | + ], settings); |
| 219 | + |
| 220 | + await assertDynamicLinks(getDocumentUri('./'), `@import '@BothDir/_foo'`, [ |
| 221 | + { range: newRange(8, 23), target: getDocumentUri('./both/_foo.scss') } |
| 222 | + ], settings); |
| 223 | + }); |
| 224 | + |
180 | 225 | test('SCSS module file links', async () => {
|
181 | 226 | const fixtureRoot = path.resolve(__dirname, '../../../../src/test/scss/linkFixture/module');
|
182 | 227 | const getDocumentUri = (relativePath: string) => {
|
|
0 commit comments