Skip to content

Commit

Permalink
Fixes #312
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-bsaviano committed Apr 1, 2024
1 parent 5f7fec2 commit fb3b168
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## [2.4.5] - 2024-XX-XX
- Fix issue [#312](https://github.com/intersystems/language-server/issues/312): Fix routine existence diagnostics for routines that only exist in OBJ form
- Parser changes:
- DP-430347: Track variables in routine procedure blocks

Expand Down
28 changes: 17 additions & 11 deletions server/src/providers/diagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
normalizeClassname,
quoteUDLIdentifier
} from '../utils/functions';
import { zutilFunctions, lexerLanguages, documents } from '../utils/variables';
import { zutilFunctions, lexerLanguages, documents, connection } from '../utils/variables';
import { ServerSpec, StudioOpenDialogFile, QueryData } from '../utils/types';
import * as ld from '../utils/languageDefinitions';
import parameterTypes = require("../documentation/parameterTypes.json");
Expand Down Expand Up @@ -51,7 +51,7 @@ export async function onDiagnostics(params: DocumentDiagnosticParams): Promise<D
if (doc === undefined) throw new Error("Unknown document");
const parsed = await getParsedDocument(params.textDocument.uri);
if (parsed === undefined) throw new Error("Document not parsed");

connection.console.warn("got doc and parsed");
const server: ServerSpec = await getServerSpec(doc.uri);
const settings = await getLanguageServerSettings(doc.uri);
let diagnostics: Diagnostic[] = [];
Expand All @@ -68,8 +68,10 @@ export async function onDiagnostics(params: DocumentDiagnosticParams): Promise<D
if (settings.diagnostics.routines && (settings.diagnostics.classes || settings.diagnostics.deprecation)) {
// Get all classes and routines
querydata = {
query: "SELECT Name||'.cls' AS Name FROM %Dictionary.ClassDefinition UNION ALL %PARALLEL SELECT Name FROM %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?)",
parameters: ["*.mac,*.inc,*.int",1,1,1,1,0,0]
query: "SELECT Name||'.cls' AS Name FROM %Dictionary.ClassDefinition UNION ALL %PARALLEL " +
"SELECT DISTINCT BY ($PIECE(Name,'.',1,$LENGTH(Name,'.')-1)) Name FROM %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?,?) " +
"UNION ALL %PARALLEL SELECT Name FROM %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?)",
parameters: ["*.mac,*.int,*.obj",1,1,1,1,1,0,"NOT (Name %PATTERN '.E1\".\"0.1\"G\"1N1\".obj\"' AND $LENGTH(Name,'.') > 3)","*.inc",1,1,1,1,0,0]
};
}
else if (!settings.diagnostics.routines && (settings.diagnostics.classes || settings.diagnostics.deprecation)) {
Expand All @@ -82,10 +84,12 @@ export async function onDiagnostics(params: DocumentDiagnosticParams): Promise<D
else {
// Get all routines
querydata = {
query: "SELECT Name FROM %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?)",
parameters: ["*.mac,*.inc,*.int",1,1,1,1,0,0]
query: "SELECT DISTINCT BY ($PIECE(Name,'.',1,$LENGTH(Name,'.')-1)) Name FROM %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?,?) " +
"UNION ALL %PARALLEL SELECT Name FROM %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?)",
parameters: ["*.mac,*.int,*.obj",1,1,1,1,1,0,"NOT (Name %PATTERN '.E1\".\"0.1\"G\"1N1\".obj\"' AND $LENGTH(Name,'.') > 3)","*.inc",1,1,1,1,0,0]
};
}
connection.console.warn("about to send REST request");
const respdata = await makeRESTRequest("POST",1,"/action/query",server,querydata);
if (Array.isArray(respdata?.data?.result?.content)) {
files = respdata.data.result.content;
Expand Down Expand Up @@ -593,7 +597,8 @@ export async function onDiagnostics(params: DocumentDiagnosticParams): Promise<D
}
}
else {
if (!files.some(file => (file.Name == (word+".mac")) || (file.Name == (word+".int")))) {
const regex = new RegExp(`^${word}\.(mac|int|obj)$`);
if (!files.some(file => regex.test(file.Name))) {
let diagnostic: Diagnostic = {
severity: DiagnosticSeverity.Error,
range: wordrange,
Expand Down Expand Up @@ -995,7 +1000,8 @@ export async function onDiagnostics(params: DocumentDiagnosticParams): Promise<D
break;
default:
otherRtns.push(doc);
otherRtns.push(`${doc.slice(0,-3)}.int`);
otherRtns.push(`${doc.slice(0,-3)}int`);
otherRtns.push(`${doc.slice(0,-3)}obj`);
}
}
});
Expand All @@ -1005,7 +1011,7 @@ export async function onDiagnostics(params: DocumentDiagnosticParams): Promise<D
query: "SELECT Name||'.cls' AS Name FROM %Dictionary.ClassDefinition WHERE Name %INLIST $LISTFROMSTRING(?) " +
"UNION ALL %PARALLEL " +
"SELECT Name FROM %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?) WHERE Name %INLIST $LISTFROMSTRING(?)",
parameters: [otherClasses.join(","),"*.mac,*.inc,*.int",1,1,1,1,0,0,otherRtns.join(",")]
parameters: [otherClasses.join(","),"*.mac,*.inc,*.int,*.obj",1,1,1,1,1,0,otherRtns.join(",")]
};
}
else if (otherClasses.length) {
Expand All @@ -1019,7 +1025,7 @@ export async function onDiagnostics(params: DocumentDiagnosticParams): Promise<D
// Check for just routines
querydata = {
query: "SELECT Name FROM %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?) WHERE Name %INLIST $LISTFROMSTRING(?)",
parameters: ["*.mac,*.inc,*.int",1,1,1,1,0,0,otherRtns.join(",")]
parameters: ["*.mac,*.inc,*.int,*.obj",1,1,1,1,1,0,otherRtns.join(",")]
};
}

Expand All @@ -1029,7 +1035,7 @@ export async function onDiagnostics(params: DocumentDiagnosticParams): Promise<D
// We got data back

// Report Diagnostics for files that aren't in the returned data
respdata.data.result.content.forEach((e) => otherNsDocs.delete(`${namespace}:::${e.Name.endsWith(".int") ? `${e.Name.slice(0,-3)}.mac` : e.Name}`));
respdata.data.result.content.forEach((e) => otherNsDocs.delete(`${namespace}:::${(e.Name.endsWith(".int") || e.Name.endsWith(".obj")) ? `${e.Name.slice(0,-3)}mac` : e.Name}`));
otherNsDocs.forEach((v,k) => {
const [ns, doc] = k.split(":::");
if (ns == namespace) {
Expand Down

0 comments on commit fb3b168

Please sign in to comment.