@@ -12,7 +12,7 @@ import { KotlinApi } from "./lspExtensions";
12
12
import { fsExists } from "./util/fsUtils" ;
13
13
import { ServerSetupParams } from "./setupParams" ;
14
14
import { RunDebugCodeLens } from "./runDebugCodeLens" ;
15
- import { MainClassRequest } from "./lspExtensions" ;
15
+ import { MainClassRequest , OverrideMemberRequest } from "./lspExtensions" ;
16
16
17
17
/** Downloads and starts the language server. */
18
18
export async function activateLanguageServer ( { context, status, config, javaInstallation } : ServerSetupParams ) : Promise < KotlinApi > {
@@ -81,6 +81,42 @@ export async function activateLanguageServer({ context, status, config, javaInst
81
81
const contentProvider = new JarClassContentProvider ( languageClient ) ;
82
82
context . subscriptions . push ( vscode . workspace . registerTextDocumentContentProvider ( "kls" , contentProvider ) ) ;
83
83
84
+ // register override members command
85
+ vscode . commands . registerCommand ( "kotlin.overrideMember" , async ( ) => {
86
+ const activeEditor = vscode . window . activeTextEditor ;
87
+ const currentDocument = activeEditor ?. document ;
88
+ // TODO: seems like we cant interact with the inner edit-fields as if it were a WorkspaceEdit object?? See if there is a way to solve this
89
+ const overrideOptions = await languageClient . sendRequest ( OverrideMemberRequest . type , {
90
+ textDocument : {
91
+ uri : currentDocument . uri . toString ( )
92
+ } ,
93
+ position : activeEditor ?. selection . start
94
+ } ) ;
95
+
96
+ // show an error message if nothing is found
97
+ if ( 0 == overrideOptions . length ) {
98
+ vscode . window . showWarningMessage ( "No overrides found for class" ) ;
99
+ return ;
100
+ }
101
+
102
+ const selected = await vscode . window . showQuickPick ( overrideOptions . map ( elem => ( {
103
+ label : elem . title ,
104
+ data : elem . edit . changes [ currentDocument . uri . toString ( ) ]
105
+ } ) ) , {
106
+ canPickMany : true ,
107
+ placeHolder : 'Select overrides'
108
+ } ) ;
109
+
110
+ // TODO: find out why we can't use vscode.workspace.applyEdit directly with the results. Probably related to the issue mentioned above
111
+ // we know all the edits are in the current document, and that each one only contain one edit, so this hack works
112
+ activeEditor . edit ( editBuilder => {
113
+ selected . forEach ( elem => {
114
+ const textEdit = elem . data [ 0 ] ;
115
+ editBuilder . insert ( textEdit . range . start , textEdit . newText ) ;
116
+ } ) ;
117
+ } ) ;
118
+ } ) ;
119
+
84
120
// Activating run/debug code lens if the debug adapter is enabled
85
121
// and we are using 'kotlin-language-server' (other language servers
86
122
// might not support the non-standard 'kotlin/mainClass' request)
@@ -93,7 +129,7 @@ export async function activateLanguageServer({ context, status, config, javaInst
93
129
return await languageClient . sendRequest ( MainClassRequest . type , {
94
130
uri : fileUri
95
131
} )
96
- } )
132
+ } ) ;
97
133
98
134
vscode . commands . registerCommand ( "kotlin.runMain" , async ( mainClass , projectRoot ) => {
99
135
vscode . debug . startDebugging ( vscode . workspace . getWorkspaceFolder ( vscode . Uri . file ( projectRoot ) ) , {
0 commit comments