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

Ignore autocomplete requests inside strings #145

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
22 changes: 18 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,24 @@ export default {
return []
}

if (!shouldTriggerAutocomplete({ activatedManually, bufferPosition, editor })) {
return []
}

if (params.scopeDescriptor) {
const scopes: string[] = params.scopeDescriptor.getScopesArray()

// we can skip certain autocomplete requests like inside strings
if (scopes.includes('string.quoted')) {
return []
}
// or template strings, unless we are inside an expression
if (scopes.includes('string.quoted.template')
&& !scopes.includes('embedded.source')) {
return []
}
}

const fileDirectory = Path.dirname(filePath)
const fileContents = injectPosition(editor.getText(), editor, bufferPosition)
let flowOptions = ['autocomplete', '--json', filePath]
Expand All @@ -326,10 +344,6 @@ export default {
prefix = ''
}

if (!shouldTriggerAutocomplete({ activatedManually, bufferPosition, editor })) {
return []
}

let result
try {
result = await exec(await this.getExecutablePath(fileDirectory), flowOptions, {
Expand Down