This repository was archived by the owner on Sep 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
server/src/lib/lsp/code-action Expand file tree Collapse file tree Original file line number Diff line number Diff 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 */
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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" ;
710import { Context } from "../context/context" ;
811import { ExtensionContext } from "../extension" ;
@@ -17,6 +20,7 @@ import { attributes } from "./types";
1720
1821import * as BehaviorPack from "./minecraft/behavior-pack/main" ;
1922import * as Minecraft from "./minecraft/code-actions" ;
23+ import * as Molang from "./minecraft/molang/main" ;
2024import * as ResourcePack from "./minecraft/resource-pack/main" ;
2125
2226export 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
You can’t perform that action at this time.
0 commit comments