Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update shouldProvide.ts #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/shouldProvide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
blackmiaool marked this conversation as resolved.
Show resolved Hide resolved
}

function isImportOrRequire(textCurrentLine: string, position: number): boolean  {
Expand Down Expand Up @@ -50,8 +51,15 @@ function startsWithADot(textCurrentLine: string, position: number) {
&& textWithinString[0] === '.';
}

function startsWithAtPath(textCurrentLine: string, position: number) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function startsWithAtPath(textCurrentLine: string, position: number) {
function startsWithAnAtSymbol(textCurrentLine: string, position: number) {

Hey, you changed the name as I suggested, but you left the function name itself unchanged.
You should update that too.
Have a nice day 😄

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that. I'm outside now so I used github's "Add suggestion to batch" function to merge your change. I'll fix it on Monday.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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;
}
}