Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
octref committed May 9, 2019
1 parent 2d0a8b9 commit 42e1831
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/services/selectorPrinting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,13 @@ function selectorToSpecificityMarkedString(node: nodes.Node): MarkedString {

export function selectorToMarkedString(node: nodes.Selector): MarkedString[] {
const root = selectorToElement(node);
const markedStrings = new MarkedStringPrinter('"').print(root);
markedStrings.push(selectorToSpecificityMarkedString(node));
return markedStrings;
if (root) {
const markedStrings = new MarkedStringPrinter('"').print(root);
markedStrings.push(selectorToSpecificityMarkedString(node));
return markedStrings;
} else {
return [];
}
}

export function simpleSelectorToMarkedString(node: nodes.SimpleSelector): MarkedString[] {
Expand Down Expand Up @@ -438,7 +442,7 @@ function isNewSelectorContext(node: nodes.Node): boolean {
return false;
}

export function selectorToElement(node: nodes.Selector): Element {
export function selectorToElement(node: nodes.Selector): Element | null {
if (node.matches('@at-root')) {
return null;
}
Expand Down
36 changes: 36 additions & 0 deletions src/test/css/hover.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

'use strict';

import * as assert from 'assert';
import { TextDocument, FoldingRange, FoldingRangeKind, Hover } from 'vscode-languageserver-types';
import { CSSHover } from '../../services/cssHover';
import { SCSSParser } from '../../parser/scssParser';

function assertSCSSHover(value: string, expected: Hover): void {
const languageId = 'scss'

let offset = value.indexOf('|');
value = value.substr(0, offset) + value.substr(offset + 1);

const hover = new CSSHover()
const document = TextDocument.create(`test://foo/bar.${languageId}`, languageId, 1, value);
const hoverResult = hover.doHover(document, document.positionAt(offset), new SCSSParser().parseStylesheet(document));

if (hoverResult.range && expected.range) {
assert.equal(hoverResult.range, expected.range);
}
assert.deepEqual(hoverResult.contents, expected.contents);
}

suite('SCSS Hover', () => {
test('@at-root', () => {

assertSCSSHover('.test { @|at-root { }', {
contents: []
})
});
});

0 comments on commit 42e1831

Please sign in to comment.