@@ -49,13 +49,15 @@ function isEsyConfiguredProperly(esyConfig: any) {
4949 } ) ;
5050}
5151
52- function isConfuguredProperly ( esyConfig : any ) {
52+ function isConfiguredProperly ( esyConfig : any , opamConfig : any ) {
5353 if ( esyConfig ) {
5454 return isEsyConfiguredProperly ( esyConfig ) ;
5555 }
5656
5757 if ( isBucklescriptProject ( ) ) return true ;
5858
59+ if ( ! ! opamConfig ) return true ;
60+
5961 vscode . window . showInformationMessage (
6062 "LSP is unable to start. Extension couldn't detect type of the project. Provide esy or bucklescript configuration. More in README." ,
6163 ) ;
@@ -64,38 +66,46 @@ function isConfuguredProperly(esyConfig: any) {
6466
6567export async function launch ( context : vscode . ExtensionContext ) : Promise < void > {
6668 const esyConfig = await getEsyConfig ( ) ;
69+ const opamConfig = await getOpamConfig ( ) ;
6770
68- if ( ! isConfuguredProperly ( esyConfig ) ) return ;
71+ if ( ! isConfiguredProperly ( esyConfig , opamConfig ) ) return ;
6972
7073 return launchMerlinLsp ( context , {
7174 useEsy : ! ! esyConfig ,
75+ useOpam : ! ! opamConfig ,
7276 } ) ;
7377}
7478
7579function getPrebuiltExecutablesPath ( ) {
7680 return path . join ( __dirname , `../../../executables/${ process . platform } ` ) ;
7781}
7882
79- function getMerlinLspPath ( useEsy : boolean ) {
83+ function getMerlinLspPath ( { useEsy : boolean , useOpam : boolean } ) {
8084 let merlinLspPath = isWin ? "ocamlmerlin-lsp.exe" : "ocamlmerlin-lsp" ;
8185
82- if ( ! useEsy ) {
86+ if ( ! useEsy && ! useOpam ) {
8387 merlinLspPath = path . join ( getPrebuiltExecutablesPath ( ) , merlinLspPath ) ;
8488 }
8589
8690 return merlinLspPath ;
8791}
8892
89- function getMerlinLspOptions ( options : { useEsy : boolean } ) {
90- const merlinLsp = getMerlinLspPath ( options . useEsy ) ;
91- const pth = options . useEsy ? process . env . PATH : `${ getPrebuiltExecutablesPath ( ) } :${ process . env . PATH } ` ;
93+ function getMerlinLspOptions ( options : { useEsy : boolean , useOpam : boolean } ) {
94+ const merlinLsp = getMerlinLspPath ( options ) ;
95+ const usePkgManager = options . useEsy || options . useOpam ;
96+ const pth = usePkgManager ? process . env . PATH : `${ getPrebuiltExecutablesPath ( ) } :${ process . env . PATH } ` ;
9297
9398 let run ;
9499 if ( options . useEsy ) {
95100 run = {
96101 args : [ "exec-command" , "--include-current-env" , merlinLsp ] ,
97102 command : process . platform === "win32" ? "esy.cmd" : "esy" ,
98103 } ;
104+ } else {
105+ run = {
106+ args : [ "exec-command" , "exec" , "--" , merlinLsp ] ,
107+ command : "opam" ,
108+ } ;
99109 } else {
100110 run = {
101111 args : [ ] ,
@@ -132,7 +142,7 @@ function getMerlinLspOptions(options: { useEsy: boolean }) {
132142 return serverOptions ;
133143}
134144
135- export async function launchMerlinLsp ( context : vscode . ExtensionContext , options : { useEsy : boolean } ) : Promise < void > {
145+ export async function launchMerlinLsp ( context : vscode . ExtensionContext , options : { useEsy : boolean , useOpam : boolean } ) : Promise < void > {
136146 const serverOptions = getMerlinLspOptions ( options ) ;
137147 const reasonConfig = vscode . workspace . getConfiguration ( "reason" ) ;
138148
0 commit comments