diff options
author | bscan <10503608+bscan@users.noreply.github.com> | 2023-10-20 09:19:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-20 09:19:31 -0400 |
commit | 6f9b70b6ff248a343c97dd5d266d6ce248fe162f (patch) | |
tree | dc937d64494205c83d30fa780892cd2875100a9a | |
parent | 447de326a6348bb8c2180b2edd22d74cfb21704c (diff) | |
parent | 43de8f5edc4b394edbafd88265510b18cb5f7a5b (diff) | |
download | PerlNavigator-6f9b70b6ff248a343c97dd5d266d6ce248fe162f.zip |
Merge pull request #100 from IAKOBVS/main
refactor: reduce overkill uses of regex
-rw-r--r-- | server/src/diagnostics.ts | 2 | ||||
-rw-r--r-- | server/src/hover.ts | 2 | ||||
-rw-r--r-- | server/src/parser.ts | 4 | ||||
-rw-r--r-- | server/src/signatures.ts | 2 | ||||
-rw-r--r-- | server/src/symbols.ts | 2 |
5 files changed, 6 insertions, 6 deletions
diff --git a/server/src/diagnostics.ts b/server/src/diagnostics.ts index 05e698f..b74902c 100644 --- a/server/src/diagnostics.ts +++ b/server/src/diagnostics.ts @@ -82,7 +82,7 @@ function getAdjustedPerlCode(textDocument: TextDocument, filePath: string): stri const module_name = module_name_match[1]; const inc_filename = module_name.replaceAll("::", "/") + ".pm"; // make sure the package found actually matches the filename - if (filePath.match(".*" + inc_filename)) { + if (filePath.indexOf(inc_filename) != -1) { register_inc_path = `\$INC{'${inc_filename}'} = '${filePath}';`; break; } else { diff --git a/server/src/hover.ts b/server/src/hover.ts index 30abd5f..930a8e6 100644 --- a/server/src/hover.ts +++ b/server/src/hover.ts @@ -42,7 +42,7 @@ function buildHoverDoc(symbol: string, elem: PerlElem, refined: PerlElem | undef if (refined && refined.signature) { let signature = refined.signature; signature = [...signature]; - if (symbol.match(/\->/) && refined.type != PerlSymbolKind.LocalMethod) { + if (symbol.indexOf("->") != -1 && refined.type != PerlSymbolKind.LocalMethod) { signature.shift(); name = name.replace(/::(\w+)$/, "->$1"); } diff --git a/server/src/parser.ts b/server/src/parser.ts index 252b342..3aa6b5b 100644 --- a/server/src/parser.ts +++ b/server/src/parser.ts @@ -200,7 +200,7 @@ function subs(state: ParserState): boolean { // Define subrountine signatures, but exclude prototypes // The declaration continues if the line does not end with ; - state.var_continues = !(state.stmt.match(/;$/) || state.stmt.match(/[\)\=\}\{]/)); + state.var_continues = !(state.stmt.endsWith(';') || state.stmt.match(/[\)\=\}\{]/)); for (const matchvar of vars) { signature_params.push(matchvar[1]); @@ -567,7 +567,7 @@ function PackageEndLine(state: ParserState) { if (found == false) { // If we haven't found the start of the package block, there probably isn't one. - if (stmt.match(/;/) || i - start_line > 1) { + if (stmt.indexOf(';') != -1 || i - start_line > 1) { break; } } diff --git a/server/src/signatures.ts b/server/src/signatures.ts index dcf48ff..a295eb8 100644 --- a/server/src/signatures.ts +++ b/server/src/signatures.ts @@ -51,7 +51,7 @@ function buildSignature(elem: PerlElem, currentSig: string, symbol: string): Sig if (!params) return; params = [...params]; // Clone to ensure we don't modify the original let activeParameter = (currentSig.match(/,/g) || []).length; - if (symbol.match(/->/) && elem.type != PerlSymbolKind.LocalMethod) { + if (symbol.indexOf("->") != -1 && elem.type != PerlSymbolKind.LocalMethod) { // Subroutine vs method is not relevant, only matters if you called it as a method (except Corinna, for which $self is implicit) params.shift(); // function_name = function_name.replace(/::(\w+)$/, '->$1'); diff --git a/server/src/symbols.ts b/server/src/symbols.ts index 116a520..32105d7 100644 --- a/server/src/symbols.ts +++ b/server/src/symbols.ts @@ -71,7 +71,7 @@ export function getWorkspaceSymbols(params: WorkspaceSymbolParams, defaultMods: return new Promise((resolve, reject) => { let symbols: SymbolInformation[] = []; - const lcQuery = params.query.toLowerCase(); + // const lcQuery = params.query.toLowerCase(); // Currently unused. defaultMods.forEach((modUri: string, modName: string) => { if (true) { // Just send the whole list and let the client sort through it with fuzzy search |