Skip to content

Commit 0708946

Browse files
committed
Prevent snippets when inside of a string
1 parent c06a282 commit 0708946

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,4 @@ Type part of a snippet, press `tab` or `enter` to autofill the rest.
160160

161161
### Contributions
162162

163-
If you want any additional configurations or features feel free to either open an issue or pull request
163+
If you want any additional configurations or features feel free to either [open an issue](https://github.com/OwenFlood/arduino-snippets/issues) or [pull request](https://github.com/OwenFlood/arduino-snippets/pulls)

out/arduino-snippets.js

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/arduino-snippets.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

snippets/arduino-snippets.ts

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ export function activate(context: vscode.ExtensionContext) {
88
provideCompletionItems(doc, pos, token, context) {
99
let sameLineCurly = vscode.workspace.getConfiguration("arduino-snippets-plus").get("same-line-curlies");
1010

11+
const string = doc.getText( // Contents of file up to current location
12+
new vscode.Range(
13+
new vscode.Position(0, 0),
14+
new vscode.Position(pos.line, pos.character)
15+
)
16+
);
17+
// | Number of quotations | - | Escaped quotations |
18+
const isInQuote = !!((string.split('"').length - string.split('\\"').length) % 2);
19+
20+
if (isInQuote) { // Prevent returning snippets if cursor is in a string
21+
return [];
22+
}
23+
1124
return snippets.map(({ prefix, body, description }) => {
1225
if (sameLineCurly && ~body.indexOf("\n{")) { // Searches body for presence of newline before curly
1326
body = body.replace(/\n{/g, ' {');

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"rootDir": "snippets",
99
"resolveJsonModule": true,
1010
"esModuleInterop": true,
11+
"removeComments": true,
1112
"strict": true /* enable all strict type-checking options */
1213
/* Additional Checks */
1314
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */

0 commit comments

Comments
 (0)