Skip to content

Commit

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

## [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
- Fix issue [#313](https://github.com/intersystems/language-server/issues/313): Add Diagnostic when `ROUTINE` header is missing
- Parser changes:
- DP-430347: Track variables in routine procedure blocks
- DP-430473: Fix variable tracking with embedded SQL in routine procedure blocks
Expand Down
13 changes: 12 additions & 1 deletion client/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
Position,
DocumentSymbol,
TextEditorRevealType,
Selection
Selection,
TextEditor,
TextEditorEdit
} from 'vscode';

import { WorkspaceEdit, TextEdit } from 'vscode-languageclient/node';
Expand Down Expand Up @@ -307,3 +309,12 @@ export async function showSymbolInClass(uri: string, memberType: string, memberN
editor.revealRange(symbol.selectionRange, TextEditorRevealType.InCenter);
}
}

/**
* Callback function for the `intersystems.language-server.setSelection` command.
*/
export function setSelection(editor: TextEditor, _edit: TextEditorEdit, startLine: number, startCharacter: number, endLine: number, endCharacter: number) {
const range = new Range(startLine,startCharacter,endLine,endCharacter);
editor.selection = new Selection(range.start, range.end);
editor.revealRange(range, TextEditorRevealType.InCenter);
}
4 changes: 3 additions & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import {
showSymbolInClass,
overrideClassMembers,
selectImportPackage,
selectParameterType
selectParameterType,
setSelection
} from './commands';
import { makeRESTRequest, ServerSpec } from './makeRESTRequest';
import { ISCEmbeddedContentProvider, requestForwardingMiddleware } from './requestForwarding';
Expand Down Expand Up @@ -246,6 +247,7 @@ export async function activate(context: ExtensionContext) {
commands.registerCommand("intersystems.language-server.selectImportPackage",selectImportPackage),
commands.registerCommand("intersystems.language-server.extractMethod",extractMethod),
commands.registerCommand("intersystems.language-server.showSymbolInClass",showSymbolInClass),
commands.registerTextEditorCommand("intersystems.language-server.setSelection",setSelection),

// Register EvaluatableExpressionProvider
languages.registerEvaluatableExpressionProvider(documentSelector,new ObjectScriptEvaluatableExpressionProvider()),
Expand Down
10 changes: 10 additions & 0 deletions server/src/providers/diagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ export async function onDiagnostics(params: DocumentDiagnosticParams): Promise<D
// The document begins with "ROUTINE" (case-insensitive)
doc.getText(Range.create(Position.create(0,parsed[0][0].p),Position.create(0,parsed[0][0].p+parsed[0][0].c))).toLowerCase() === "routine";

if (!firstlineisroutine && ["objectscript","objectscript-int","objectscript-macros"].includes(doc.languageId)) {
// The ROUTINE header is required
diagnostics.push({
severity: DiagnosticSeverity.Error,
range: Range.create(0,0,0,0),
message: "ROUTINE header is required",
source: "InterSystems Language Server"
});
}

const startline: number = (firstlineisroutine) ? 1 : 0;

// Store the name, class and ranges for all class members that we see if settings.diagnostics.deprecation is true
Expand Down
28 changes: 26 additions & 2 deletions server/src/providers/refactoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1441,7 +1441,7 @@ export async function onCodeAction(params: CodeActionParams): Promise<CodeAction
const settings = await getLanguageServerSettings(doc.uri);

var result: CodeAction[] = [];
if (params.context.only !== undefined && params.context.only.includes(CodeActionKind.Refactor)) {
if (!Array.isArray(params.context.only) || params.context.only.includes(CodeActionKind.Refactor)) {
result.push({
title: 'Wrap in Try/Catch',
kind: CodeActionKind.Refactor
Expand Down Expand Up @@ -1606,7 +1606,7 @@ export async function onCodeAction(params: CodeActionParams): Promise<CodeAction
};
}
result[0].data = [doc.uri,lnstart,lnend];
} else if (params.context.only !== undefined && params.context.only.includes(CodeActionKind.QuickFix)) {
} else if (!Array.isArray(params.context.only) || params.context.only.includes(CodeActionKind.QuickFix)) {
for (const diagnostic of params.context.diagnostics) {
if (
diagnostic.message === "Invalid parameter type." ||
Expand Down Expand Up @@ -1670,9 +1670,33 @@ export async function onCodeAction(params: CodeActionParams): Promise<CodeAction
}]
}
},
isPreferred: true,
diagnostics: [diagnostic]
});
}
} else if (diagnostic.message == "ROUTINE header is required") {
const rtnType = doc.languageId == "objectscript-int" ? "Type=INT" : doc.languageId == "objectscript-macros" ? "Type=INC" : "";
const rtnName = doc.uri.slice(doc.uri.lastIndexOf("/") + 1).split(".").slice(0,-1).join(".");
const rtnGenerated = doc.languageId == "objectscript-int" && /\.G?\d$/.test(rtnName) ? ",Generated" : "";
result.push({
title: "Add header",
kind: CodeActionKind.QuickFix,
edit: {
changes: {
[params.textDocument.uri]: [{
range: diagnostic.range,
newText: `ROUTINE ${rtnName}${rtnType != "" ? ` [${rtnType}${rtnGenerated}]` : ""}\n`
}]
}
},
command: {
command: "intersystems.language-server.setSelection",
arguments: [0, 8, 0, 8 + rtnName.length],
title: "Set selection"
},
isPreferred: true,
diagnostics: [diagnostic]
});
}
}
}
Expand Down

0 comments on commit 7f58498

Please sign in to comment.