Skip to content

Commit

Permalink
styles: invert isVueFile condition and add Region type
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyo930021 committed Jan 5, 2020
1 parent 28dd9ce commit ad2297c
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/utils/vue.ts
Original file line number Diff line number Diff line change
@@ -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 = /<style[\w=\"\' \n\t]{1,}lang=[\"\']scss[\"\'][\w=\"\' \n\t]{0,}>/g;
const endRe = /<\/style>/g;
/* tslint:disable:no-conditional-assignment */
Expand All @@ -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 };
}

0 comments on commit ad2297c

Please sign in to comment.