From 5a44d549ad809bb90cf78fea4b052ca32840f6c2 Mon Sep 17 00:00:00 2001 From: blackmiaool Date: Sun, 15 Apr 2018 18:31:13 +0800 Subject: [PATCH 1/2] Update shouldProvide.ts For some paths like "@/a.js". It's very common in vue-cli project. --- src/shouldProvide.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/shouldProvide.ts b/src/shouldProvide.ts index e633148..a13d8fe 100644 --- a/src/shouldProvide.ts +++ b/src/shouldProvide.ts @@ -2,7 +2,8 @@ import { State } from './State'; export function shouldProvide(state: State) { return isImportOrRequire(state.textCurrentLine, state.cursorPosition) - && !startsWithADot(state.textCurrentLine, state.cursorPosition); + && !startsWithADot(state.textCurrentLine, state.cursorPosition) + && !startsWithAtPath(state.textCurrentLine, state.cursorPosition); } function isImportOrRequire(textCurrentLine: string, position: number): boolean  { @@ -50,8 +51,15 @@ function startsWithADot(textCurrentLine: string, position: number) { && textWithinString[0] === '.'; } +function startsWithAtPath(textCurrentLine: string, position: number) { + const textWithinString = getTextWithinString(textCurrentLine, position); + return textWithinString + && textWithinString.length > 0 + && /^@[\/]/.test(textWithinString); +} + function getTextWithinString(text: string, position: number): string { const textToPosition = text.substring(0, position); const quoatationPosition = Math.max(textToPosition.lastIndexOf('\"'), textToPosition.lastIndexOf('\'')); return quoatationPosition != -1 ? textToPosition.substring(quoatationPosition + 1, textToPosition.length) : undefined; -} \ No newline at end of file +} From 77358950ae7b4338c400a0268dbd5878caba6563 Mon Sep 17 00:00:00 2001 From: MarvinJWendt Date: Sat, 8 Dec 2018 00:48:41 -0600 Subject: [PATCH 2/2] Apply suggestions from code review Co-Authored-By: blackmiaool --- src/shouldProvide.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shouldProvide.ts b/src/shouldProvide.ts index a13d8fe..8a2fa2a 100644 --- a/src/shouldProvide.ts +++ b/src/shouldProvide.ts @@ -3,7 +3,7 @@ import { State } from './State'; export function shouldProvide(state: State) { return isImportOrRequire(state.textCurrentLine, state.cursorPosition) && !startsWithADot(state.textCurrentLine, state.cursorPosition) - && !startsWithAtPath(state.textCurrentLine, state.cursorPosition); + && !startsWithAnAtSymbol(state.textCurrentLine, state.cursorPosition); } function isImportOrRequire(textCurrentLine: string, position: number): boolean  { @@ -51,7 +51,7 @@ function startsWithADot(textCurrentLine: string, position: number) { && textWithinString[0] === '.'; } -function startsWithAtPath(textCurrentLine: string, position: number) { +function startsWithAnAtSymbol(textCurrentLine: string, position: number) { const textWithinString = getTextWithinString(textCurrentLine, position); return textWithinString && textWithinString.length > 0