Skip to content

Commit

Permalink
Merge pull request #161 from Danp2/fix_symbols
Browse files Browse the repository at this point in the history
ai_symbols - Regex improvements
  • Loading branch information
loganch authored Feb 19, 2023
2 parents 9a0615c + 63791b8 commit da3108d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/ai_symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(?<funcName>${functionName}\\b).*\\n(?:(?!EndFunc\\b).*\\n)*EndFunc.*\\n?`
`Func\\s+\\b(?<funcName>${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;
Expand Down Expand Up @@ -98,13 +102,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;
}

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit da3108d

Please sign in to comment.