From ad2297c0ed1cdbe58e8243a0e8dbb524f08a6d9f Mon Sep 17 00:00:00 2001 From: yoyo930021 Date: Sun, 5 Jan 2020 17:10:51 +0800 Subject: [PATCH] styles: invert isVueFile condition and add Region type --- src/utils/vue.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/utils/vue.ts b/src/utils/vue.ts index 909838c5..0bb3bdd0 100644 --- a/src/utils/vue.ts +++ b/src/utils/vue.ts @@ -1,11 +1,13 @@ import { TextDocument, Position } from 'vscode-languageserver'; +type Region = [number, number]; + export function isVueFile(path: string) { return path.endsWith('.vue'); } export function getVueSCSSRegions(content: string) { - const regions: Array<[number, number]> = []; + const regions: Region[] = []; const startRe = //g; const endRe = /<\/style>/g; /* tslint:disable:no-conditional-assignment */ @@ -32,19 +34,17 @@ export function getVueSCSSContent(content: string, regions = getVueSCSSRegions(c return newContent; } -function convertVueTextDocument(document: TextDocument, regions: Array<[number, number]>) { +function convertVueTextDocument(document: TextDocument, regions: Region[]) { return TextDocument.create(document.uri, 'scss', document.version, getVueSCSSContent(document.getText(), regions)); } export function getSCSSRegionsDocument(document: TextDocument, position: Position) { const offset = document.offsetAt(position); - if (isVueFile(document.uri)) { - const vueSCSSRegions = getVueSCSSRegions(document.getText()); - if (vueSCSSRegions.some(region => region[0] <= offset && region[1] >= offset)) { - return { document: convertVueTextDocument(document, vueSCSSRegions), offset }; - } - return { document: null, offset }; - } + if (!isVueFile(document.uri)) { return { document, offset }; } - return { document, offset }; + const vueSCSSRegions = getVueSCSSRegions(document.getText()); + if (vueSCSSRegions.some(region => region[0] <= offset && region[1] >= offset)) { + return { document: convertVueTextDocument(document, vueSCSSRegions), offset }; + } + return { document: null, offset }; }