Skip to content
This repository was archived by the owner on Sep 28, 2025. It is now read-only.

Commit 3dfa3b9

Browse files
committed
feat: adding molang deprecated code actions
1 parent 031d493 commit 3dfa3b9

4 files changed

Lines changed: 49 additions & 3 deletions

File tree

server/src/lib/lsp/code-action/builder.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class CodeActionBuilder {
3535
}
3636

3737
/** */
38-
push(item: Command | CodeAction | undefined): Command | CodeAction | undefined {
38+
push<T extends Command | CodeAction | undefined>(item: T): T {
3939
if (item) {
4040
this.out.push(item);
4141
}
@@ -59,7 +59,7 @@ export class CodeActionBuilder {
5959
}
6060

6161
/**
62-
*
62+
* Creates a new action, with the given title
6363
* @param title
6464
* @returns
6565
*/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { CodeActionKind, Diagnostic, TextEdit } from "vscode-languageserver";
2+
import { CodeActionBuilder } from "../../builder";
3+
import { MolangData } from "bc-minecraft-molang";
4+
5+
export function onCodeAction(builder: CodeActionBuilder, diag: Diagnostic) {
6+
const id = builder.getText(diag.range);
7+
if (id === "") return;
8+
9+
const [scope, fnName] = id.split(".");
10+
11+
const data = scope.startsWith("q") ? MolangData.General.getQuery(fnName) : MolangData.General.getMath(fnName);
12+
if (!data || !data.deprecated) return;
13+
if (!data.deprecated.startsWith("q") && !data.deprecated.startsWith("m")) return;
14+
15+
const newId = data.deprecated;
16+
builder.push({
17+
title: "Replace with: " + newId,
18+
kind: CodeActionKind.QuickFix,
19+
diagnostics: [diag],
20+
isPreferred: true,
21+
edit: {
22+
changes: {
23+
[builder.context.document.uri]: [TextEdit.replace(diag.range, newId)],
24+
},
25+
},
26+
});
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Diagnostic } from "vscode-languageserver";
2+
import { CodeActionBuilder } from "../../builder";
3+
4+
import * as Deprecated from "./deprecated";
5+
6+
export function onCodeAction(builder: CodeActionBuilder, diag: Diagnostic): void {
7+
switch (diag.code) {
8+
case "molang.function.deprecated":
9+
return Deprecated.onCodeAction(builder, diag);
10+
}
11+
}

server/src/lib/lsp/code-action/service.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import {
22
CancellationToken,
33
CodeAction,
44
CodeActionParams,
5-
Command, Connection, Diagnostic, WorkDoneProgressReporter
5+
Command,
6+
Connection,
7+
Diagnostic,
8+
WorkDoneProgressReporter,
69
} from "vscode-languageserver";
710
import { Context } from "../context/context";
811
import { ExtensionContext } from "../extension";
@@ -17,6 +20,7 @@ import { attributes } from "./types";
1720

1821
import * as BehaviorPack from "./minecraft/behavior-pack/main";
1922
import * as Minecraft from "./minecraft/code-actions";
23+
import * as Molang from "./minecraft/molang/main";
2024
import * as ResourcePack from "./minecraft/resource-pack/main";
2125

2226
export class CodeActionService extends BaseService implements Partial<IService> {
@@ -94,6 +98,10 @@ export class CodeActionService extends BaseService implements Partial<IService>
9498
Minecraft.onCodeAction(builder, diag);
9599
break;
96100

101+
case "molang":
102+
Molang.onCodeAction(builder, diag);
103+
break;
104+
97105
case "mcfunction":
98106
}
99107

0 commit comments

Comments
 (0)