@@ -12,7 +12,7 @@ import { KotlinApi } from "./lspExtensions";
1212import  {  fsExists  }  from  "./util/fsUtils" ; 
1313import  {  ServerSetupParams  }  from  "./setupParams" ; 
1414import  {  RunDebugCodeLens  }  from  "./runDebugCodeLens" ; 
15- import  {  MainClassRequest  }  from  "./lspExtensions" ; 
15+ import  {  MainClassRequest ,   OverrideMemberRequest  }  from  "./lspExtensions" ; 
1616
1717/** Downloads and starts the language server. */ 
1818export  async  function  activateLanguageServer ( {  context,  status,  config,  javaInstallation } : ServerSetupParams ) : Promise < KotlinApi >  { 
@@ -81,6 +81,42 @@ export async function activateLanguageServer({ context, status, config, javaInst
8181    const  contentProvider  =  new  JarClassContentProvider ( languageClient ) ; 
8282    context . subscriptions . push ( vscode . workspace . registerTextDocumentContentProvider ( "kls" ,  contentProvider ) ) ; 
8383
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+ 
84120    // Activating run/debug code lens if the debug adapter is enabled 
85121    // and we are using 'kotlin-language-server' (other language servers 
86122    // might not support the non-standard 'kotlin/mainClass' request) 
@@ -93,7 +129,7 @@ export async function activateLanguageServer({ context, status, config, javaInst
93129            return  await  languageClient . sendRequest ( MainClassRequest . type ,  { 
94130                uri : fileUri 
95131            } ) 
96-         } ) 
132+         } ) ; 
97133
98134        vscode . commands . registerCommand ( "kotlin.runMain" ,  async ( mainClass ,  projectRoot )  =>  { 
99135            vscode . debug . startDebugging ( vscode . workspace . getWorkspaceFolder ( vscode . Uri . file ( projectRoot ) ) ,  { 
0 commit comments