summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Tirta Halim <tirtajames45@gmail.com>2023-10-17 21:24:39 +0700
committerJames Tirta Halim <tirtajames45@gmail.com>2023-10-17 21:24:39 +0700
commit37dff3484e865f5b0f798f7b55f59512bd438632 (patch)
tree21ec0c8d9370be9191dd0f76e7a512b528f2c32e
parent447de326a6348bb8c2180b2edd22d74cfb21704c (diff)
downloadPerlNavigator-37dff3484e865f5b0f798f7b55f59512bd438632.zip
refactor: reduce overkill use of regex
-rw-r--r--server/src/diagnostics.ts2
-rw-r--r--server/src/hover.ts2
-rw-r--r--server/src/parser.ts4
-rw-r--r--server/src/signatures.ts2
4 files changed, 5 insertions, 5 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');