Skip to content

Commit 1625bbe

Browse files
committed
deprecated functions, quick fix for $zobjxxx, ignore commands in &sql
1 parent 2c91451 commit 1625bbe

File tree

5 files changed

+153
-8
lines changed

5 files changed

+153
-8
lines changed

src/extension.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export let panel: vscode.StatusBarItem;
6363
export let terminal: vscode.Terminal;
6464

6565
import TelemetryReporter from "vscode-extension-telemetry";
66+
import { CodeActionProvider } from "./providers/CodeActionProvider";
6667

6768
const packageJson = vscode.extensions.getExtension(extensionId).packageJSON;
6869
const extensionVersion = packageJson.version;
@@ -312,6 +313,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
312313
vscode.languages.setLanguageConfiguration("objectscript-class", getLanguageConfiguration("class")),
313314
vscode.languages.setLanguageConfiguration("objectscript", getLanguageConfiguration("routine")),
314315
vscode.languages.setLanguageConfiguration("objectscript-macros", getLanguageConfiguration("routine")),
316+
vscode.languages.registerCodeActionsProvider(
317+
documentSelector("objectscript-class", "objectscript"),
318+
new CodeActionProvider()
319+
),
315320
vscode.languages.registerDocumentSymbolProvider(
316321
documentSelector("objectscript-class"),
317322
new ObjectScriptClassSymbolProvider()

src/providers/CodeActionProvider.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import * as vscode from "vscode";
2+
import { Formatter } from "./Formatter";
3+
4+
export class CodeActionProvider implements vscode.CodeActionProvider {
5+
private _formatter: Formatter;
6+
public constructor() {
7+
this._formatter = new Formatter();
8+
}
9+
10+
public provideCodeActions(
11+
document: vscode.TextDocument,
12+
range: vscode.Range | vscode.Selection,
13+
context: vscode.CodeActionContext,
14+
token: vscode.CancellationToken
15+
): vscode.ProviderResult<(vscode.Command | vscode.CodeAction)[]> {
16+
const codeActions: vscode.CodeAction[] = [];
17+
context.diagnostics.forEach(diagnostic => {
18+
if (diagnostic.code === "$zobjxxx") {
19+
const text = document.getText(diagnostic.range).toLowerCase();
20+
let replacement = "";
21+
switch (text) {
22+
case "$zobjclassmethod":
23+
replacement = "$classmethod";
24+
break;
25+
case "$zobjmethod":
26+
replacement = "$method";
27+
break;
28+
case "$zobjproperty":
29+
replacement = "$property";
30+
break;
31+
case "$zobjclass":
32+
replacement = "$classname";
33+
break;
34+
default:
35+
}
36+
if (replacement.length) {
37+
replacement = this._formatter.function(replacement);
38+
codeActions.push(this.createFix(document, diagnostic.range, replacement));
39+
}
40+
}
41+
});
42+
return codeActions;
43+
}
44+
45+
private createFix(document: vscode.TextDocument, range: vscode.Range, replacement: string): vscode.CodeAction {
46+
const fix = new vscode.CodeAction(`Replace with ${replacement}`, vscode.CodeActionKind.QuickFix);
47+
fix.edit = new vscode.WorkspaceEdit();
48+
fix.edit.replace(document.uri, range, replacement);
49+
return fix;
50+
}
51+
}

src/providers/ObjectScriptDiagnosticProvider.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ export class ObjectScriptDiagnosticProvider {
9696
let endingComma = false;
9797
let isCode = !isClass;
9898
let jsScript = false;
99+
let sql = false;
100+
let sqlParens = 0;
99101
for (let i = 0; i < document.lineCount; i++) {
100102
const line = document.lineAt(i);
101103
const text = this.stripLineComments(line.text);
@@ -106,6 +108,19 @@ export class ObjectScriptDiagnosticProvider {
106108
jsScript = true;
107109
}
108110

111+
if (text.match("&sql")) {
112+
sql = true;
113+
sqlParens = 0;
114+
}
115+
116+
if (sql) {
117+
sqlParens = sqlParens + (text.split("(").length - 1) - (text.split(")").length - 1);
118+
if (sqlParens <= 0) {
119+
sql = false;
120+
}
121+
continue;
122+
}
123+
109124
if (jsScript) {
110125
if (text.match(/<\/script>/)) {
111126
jsScript = false;
@@ -151,8 +166,9 @@ export class ObjectScriptDiagnosticProvider {
151166
code: "",
152167
message: "Unrecognized command",
153168
range,
154-
severity: vscode.DiagnosticSeverity.Error,
155-
source: "",
169+
severity: found.toUpperCase().startsWith("Z")
170+
? vscode.DiagnosticSeverity.Warning
171+
: vscode.DiagnosticSeverity.Error,
156172
relatedInformation: [
157173
new vscode.DiagnosticRelatedInformation(
158174
new vscode.Location(document.uri, range),
@@ -211,11 +227,11 @@ export class ObjectScriptDiagnosticProvider {
211227
);
212228
if (!systemFunction) {
213229
result.push({
214-
code: "",
215-
message: "Unrecognized system function/variable",
216230
range,
217-
severity: vscode.DiagnosticSeverity.Error,
218-
source: "",
231+
message: "Unrecognized system function/variable",
232+
severity: found.toUpperCase().startsWith("$Z")
233+
? vscode.DiagnosticSeverity.Warning
234+
: vscode.DiagnosticSeverity.Error,
219235
relatedInformation: [
220236
new vscode.DiagnosticRelatedInformation(
221237
new vscode.Location(document.uri, range),
@@ -224,6 +240,21 @@ export class ObjectScriptDiagnosticProvider {
224240
],
225241
});
226242
}
243+
if (systemFunction && systemFunction.deprecated) {
244+
result.push({
245+
range,
246+
code: systemFunction.code || "",
247+
severity: vscode.DiagnosticSeverity.Warning,
248+
message: "Deprecated system function/variable",
249+
tags: [vscode.DiagnosticTag.Deprecated],
250+
relatedInformation: [
251+
new vscode.DiagnosticRelatedInformation(
252+
new vscode.Location(document.uri, range),
253+
`System function or variable '${found}' deprecated`
254+
),
255+
],
256+
});
257+
}
227258
}
228259
}
229260
return result;

src/providers/ObjectScriptHoverProvider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ export class ObjectScriptHoverProvider implements vscode.HoverProvider {
8989
}
9090
}
9191

92-
public documentationLink(link): string | null {
92+
public documentationLink(link: string): string | null {
9393
if (link) {
94-
return `[Online documenation](https://docs.intersystems.com/irislatest${link})`;
94+
return `[Online documenation](${
95+
link.startsWith("http") ? "" : "https://docs.intersystems.com/irislatest"
96+
}${link})`;
9597
}
9698
return;
9799
}

src/providers/completion/systemFunctions.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,62 @@
17741774
],
17751775
"link":"/csp/docbook/DocBook.UI.Page.cls?KEY=RCOS_fzname"
17761776
},
1777+
{
1778+
"label": "$ZOBJCLASSMETHOD",
1779+
"alias": [
1780+
"$ZOBJCLASSMETHOD"
1781+
],
1782+
"deprecated": true,
1783+
"documentation": [
1784+
"The $ZOBJCLASSMETHOD functions have been replaced with standard Caché functions. ",
1785+
"The $ZOBJCLASSMETHOD functions are still available to applications, but they are no longer documented.",
1786+
"Replaced by `$CLASSMETHOD`"
1787+
],
1788+
"link": "https://cedocs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GCRNA_upgrade20101_zobj",
1789+
"code": "$zobjxxx"
1790+
},
1791+
{
1792+
"label": "$ZOBJMETHOD",
1793+
"alias": [
1794+
"$ZOBJMETHOD"
1795+
],
1796+
"deprecated": true,
1797+
"documentation": [
1798+
"The $ZOBJMETHOD functions have been replaced with standard Caché functions. ",
1799+
"The $ZOBJMETHOD functions are still available to applications, but they are no longer documented.",
1800+
"Replaced by `$METHOD`"
1801+
],
1802+
"link": "https://cedocs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GCRNA_upgrade20101_zobj",
1803+
"code": "$zobjxxx"
1804+
},
1805+
{
1806+
"label": "$ZOBJPROPERTY",
1807+
"alias": [
1808+
"$ZOBJPROPERTY"
1809+
],
1810+
"deprecated": true,
1811+
"documentation": [
1812+
"The $ZOBJPROPERTY functions have been replaced with standard Caché functions. ",
1813+
"The $ZOBJPROPERTY functions are still available to applications, but they are no longer documented.",
1814+
"Replaced by `$PROPERTY`"
1815+
],
1816+
"link": "https://cedocs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GCRNA_upgrade20101_zobj",
1817+
"code": "$zobjxxx"
1818+
},
1819+
{
1820+
"label": "$ZOBJCLASS",
1821+
"alias": [
1822+
"$ZOBJCLASS"
1823+
],
1824+
"deprecated": true,
1825+
"documentation": [
1826+
"The $ZOBJCLASS functions have been replaced with standard Caché functions. ",
1827+
"The $ZOBJCLASS functions are still available to applications, but they are no longer documented.",
1828+
"Replaced by `$CLASSNAME`"
1829+
],
1830+
"link": "https://cedocs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GCRNA_upgrade20101_zobj",
1831+
"code": "$zobjxxx"
1832+
},
17771833
{
17781834
"label":"$ZPOSITION",
17791835
"alias":[

0 commit comments

Comments
 (0)