From c47cf21d4ecd4fb3238cc4cdde1b034f39887e99 Mon Sep 17 00:00:00 2001 From: Dan Pollak Date: Sun, 22 Jan 2023 09:52:30 -0600 Subject: [PATCH 1/2] Detect indented comment blocks --- src/ai_symbols.js | 4 ++-- src/util.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ai_symbols.js b/src/ai_symbols.js index 57e2ee3..c22bb3f 100644 --- a/src/ai_symbols.js +++ b/src/ai_symbols.js @@ -98,13 +98,13 @@ export default languages.registerDocumentSymbolProvider(AUTOIT_MODE, { continue; } - if (/^#(?:ce|comments-end)/.test(text)) { + if (/^\s*#(?:ce|comments-end)/.test(text)) { inComment = false; // eslint-disable-next-line no-continue continue; } - if (/^#(?:cs|comments-start)/.test(text)) { + if (/^\s*#(?:cs|comments-start)/.test(text)) { inComment = true; } diff --git a/src/util.js b/src/util.js index ba83d67..0499ab6 100644 --- a/src/util.js +++ b/src/util.js @@ -39,7 +39,7 @@ const isSkippableLine = line => { } if (firstChar === '#') { - if (/^#(cs|ce|comments-start|comments-end)/.test(line.text)) { + if (/^\s*#(cs|ce|comments-start|comments-end)/.test(line.text)) { return false; } return true; From 63791b873145f04172076000c7126cf45d1de638 Mon Sep 17 00:00:00 2001 From: Dan Pollak Date: Sun, 22 Jan 2023 12:51:28 -0600 Subject: [PATCH 2/2] createFunctionSymbol: Avoid commented functions by setting the position to begin searching to the start of the previously found line. --- src/ai_symbols.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ai_symbols.js b/src/ai_symbols.js index c22bb3f..05e4574 100644 --- a/src/ai_symbols.js +++ b/src/ai_symbols.js @@ -24,15 +24,19 @@ const createVariableSymbol = (variable, variableKind, doc, line, container) => { * that includes the full range of the function's body * @param {String} functionName The name of the function from the AutoIt script * @param {TextDocument} doc The current document to search - * @param {String} docText The text from the document (usually generated through `TextDocument.getText()`) + * @param {Number} lineNum The function's starting line number within the document * @returns SymbolInformation */ -const createFunctionSymbol = (functionName, doc, docText) => { +const createFunctionSymbol = (functionName, doc, lineNum) => { const pattern = new RegExp( // `^Func\\s+\\b(?${functionName}\\b).*\\n(?:(?!EndFunc\\b).*\\n)*EndFunc.*\\n?` `Func\\s+\\b(?${functionName}+\\b).*?(EndFunc)`, - 'si', + 'gsi', ); + const docText = doc.getText(); + + // Establish starting position for regex search + pattern.lastIndex = doc.offsetAt(doc.lineAt(lineNum).range.start); const result = pattern.exec(docText); if (result === null) { return null; @@ -115,7 +119,7 @@ export default languages.registerDocumentSymbolProvider(AUTOIT_MODE, { funcName = functionPattern.exec(text); if (funcName && !found.includes(funcName[0])) { - const functionSymbol = createFunctionSymbol(funcName[1], doc, doc.getText()); + const functionSymbol = createFunctionSymbol(funcName[1], doc, lineNum); if (functionSymbol) { result.push(functionSymbol);