Skip to content

Commit

Permalink
Merge branch 'main' into fix-vscode-121586
Browse files Browse the repository at this point in the history
  • Loading branch information
aeschli authored May 28, 2021
2 parents 19982f0 + 3121393 commit 86c8a58
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/services/scssNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { CSSNavigation } from './cssNavigation';
import { FileSystemProvider, DocumentContext, FileType, DocumentUri } from '../cssLanguageTypes';
import * as nodes from '../parser/cssNodes';
import { URI, Utils } from 'vscode-uri';
import { URI } from 'vscode-uri';
import { startsWith } from '../utils/strings';

export class SCSSNavigation extends CSSNavigation {
Expand Down Expand Up @@ -41,6 +41,7 @@ export class SCSSNavigation extends CSSNavigation {
}
} catch (e) {
// ignore

}
}
return target;
Expand Down
24 changes: 15 additions & 9 deletions src/test/scss/scssNavigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { assertSymbolsInScope, assertScopesAndSymbols, assertHighlights, assertC
import { getSCSSLanguageService, DocumentLink, TextDocument } from '../../cssLanguageService';
import * as assert from 'assert';
import * as path from 'path';
import { URI } from 'vscode-uri';
import { URI, Utils } from 'vscode-uri';
import { getFsProvider } from '../testUtil/fsProvider';
import { getDocumentContext } from '../testUtil/documentContext';

Expand All @@ -27,14 +27,20 @@ async function assertDynamicLinks(docUri: string, input: string, expected: Docum
assert.deepEqual(links, expected);
}

async function assertNoDynamicLinks(docUri: string, input: string) {
async function assertNoDynamicLinks(docUri: string, input: string, extecedTarget: string | undefined) {
const ls = getSCSSLS();
const document = TextDocument.create(docUri, 'scss', 0, input);

const stylesheet = ls.parseStylesheet(document);

const links = await ls.findDocumentLinks2(document, stylesheet, getDocumentContext(document.uri));
assert.deepEqual(links.length, 0, `${docUri.toString()} should have no link`);
if (extecedTarget) {
assert.deepEqual(links.length, 1, `${docUri.toString()} should only return itself`);
assert.deepEqual(links[0].target, extecedTarget, `${docUri.toString()} should only return itself`);
} else {
assert.deepEqual(links.length, 0, `${docUri.toString()} hould have no link`);
}

}

suite('SCSS - Navigation', () => {
Expand Down Expand Up @@ -111,13 +117,13 @@ suite('SCSS - Navigation', () => {
return URI.file(path.resolve(fixtureRoot, relativePath)).toString();
};

await assertNoDynamicLinks(getDocumentUri('./index.scss'), `@import 'foo'`);
await assertNoDynamicLinks(getDocumentUri('./index.scss'), `@import 'foo'`, getDocumentUri('foo'));

await assertNoDynamicLinks(getDocumentUri('./index.scss'), `@import './foo'`);
await assertNoDynamicLinks(getDocumentUri('./index.scss'), `@import './foo'`, getDocumentUri('foo'));

await assertNoDynamicLinks(getDocumentUri('./index.scss'), `@import './_foo'`);
await assertNoDynamicLinks(getDocumentUri('./index.scss'), `@import './_foo'`, getDocumentUri('_foo'));

await assertNoDynamicLinks(getDocumentUri('./index.scss'), `@import './foo-baz'`);
await assertNoDynamicLinks(getDocumentUri('./index.scss'), `@import './foo-baz'`, getDocumentUri('foo-baz'));
});

test('SCSS partial file dynamic links', async () => {
Expand Down Expand Up @@ -185,8 +191,8 @@ suite('SCSS - Navigation', () => {
{ range: newRange(9, 16), target: getDocumentUri('./foo.scss') }
]);

await assertNoDynamicLinks(getDocumentUri('./index.scss'), `@use 'sass:math'`);
await assertNoDynamicLinks(getDocumentUri('./index.scss'), `@use './non-existent'`);
await assertNoDynamicLinks(getDocumentUri('./index.scss'), `@use 'sass:math'`, undefined);
await assertNoDynamicLinks(getDocumentUri('./index.scss'), `@use './non-existent'`, getDocumentUri('non-existent'));
});

test('SCSS empty path', async () => {
Expand Down

0 comments on commit 86c8a58

Please sign in to comment.