@rescript/language-server 1.64.0 → 1.65.0-next-9d9bcf5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/analysis_binaries/darwin/rescript-editor-analysis.exe +0 -0
- package/analysis_binaries/darwinarm64/rescript-editor-analysis.exe +0 -0
- package/analysis_binaries/linux/rescript-editor-analysis.exe +0 -0
- package/analysis_binaries/linuxarm64/rescript-editor-analysis.exe +0 -0
- package/analysis_binaries/win32/rescript-editor-analysis.exe +0 -0
- package/out/cli.js +1 -1
- package/out/cli.js.map +3 -3
- package/package.json +1 -1
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/out/cli.js
CHANGED
|
@@ -43,7 +43,7 @@ ${o}`)},console.warn=function(...i){e.warn(t(i))}}});var Sr=x((uC,Fh)=>{"use str
|
|
|
43
43
|
${o?.join(" ")}
|
|
44
44
|
|
|
45
45
|
== OUTPUT ==
|
|
46
|
-
${_}`);let v={type:Gm.MessageType.Warning,message:`[Incremental typechecking] Something might have gone wrong with incremental type checking. Check out the [error log](file://${y}) and report this issue please.`};n({jsonrpc:G,method:"window/showMessage",params:v})}catch(y){console.error(y)}let H={jsonrpc:G,method:"textDocument/publishDiagnostics",params:{uri:(0,Hc.pathToFileURL)(e.file.sourceFilePath),diagnostics:re}};n(H)}r?.()});e.killCompilationListeners.push(()=>{f.kill("SIGKILL")})}catch(u){console.error(u)}}function Km(e,t,n,r){Ne()&&console.log("Updated: "+e),Q_(e,t,n,r)}function ey(e){Ne()&&console.log("Closed: "+e);let t=gn.get(e);t!=null&&(Qm(e,t.project.rootPath),gn.delete(e),Vc.delete(t.file.originalTypeFileLocation))}function ty(e){let t=gn.get(e);return t!=null?t.codeActions:null}var ny=new Set,Jc={},zc=null,Gc=!1,Qo=0,Xc=!1,Lr=new Map,sy={},J=e=>{},ay=async e=>K.extensionConfiguration.binaryPath!=null&&Ee.default.existsSync(se.join(K.extensionConfiguration.binaryPath,"rescript"))?se.join(K.extensionConfiguration.binaryPath,"rescript"):Om(e),tw=new $r.RequestType("textDocument/createInterface"),nw=new $r.RequestType("textDocument/openCompiled"),rw=e=>{let t=null;return Te.forEach((n,r)=>{t==null&&n.filesDiagnostics[e]!=null&&(t=n.filesDiagnostics[e].slice())}),t??[]},cy=async()=>{for(let[e,t]of Te){let{filesWithDiagnostics:n}=t,r=se.join(e,ec),i=Ee.default.readFileSync(r,{encoding:"utf-8"}),{done:o,result:s,codeActions:u,linesWithParseErrors:f}=await Go(i);if(f.length>0){let m={type:O.MessageType.Warning,message:`There are more compiler warning/errors that we could not parse. You can help us fix this by opening an [issue on the repository](https://github.com/rescript-lang/rescript-vscode/issues/new?title=Compiler%20log%20parse%20error), pasting the contents of the file [lib/bs/.compiler.log](file://${r}).`};J({jsonrpc:G,method:"window/showMessage",params:m})}t.filesDiagnostics=s,sy=u,Object.keys(s).forEach(m=>{let w={uri:m,diagnostics:s[m]};J({jsonrpc:G,method:"textDocument/publishDiagnostics",params:w}),n.add(m)}),o&&n.forEach(m=>{s[m]==null&&(J({jsonrpc:G,method:"textDocument/publishDiagnostics",params:{uri:m,diagnostics:[]}}),n.delete(m))})}},iw=e=>{let t=Te.get(e);t!=null&&(t.filesWithDiagnostics.forEach(n=>{J({jsonrpc:G,method:"textDocument/publishDiagnostics",params:{uri:n,diagnostics:[]}})}),Te.delete(e),K.extensionConfiguration.incrementalTypechecking?.enable&&Bc(e))},ow=()=>{J({jsonrpc:G,method:"rescript/compilationFinished"})},Kn=!1,uy=async e=>{try{Kn&&console.log("syncing project config cache for "+e),await xt(e,["cache-project",e]),Kn&&console.log("OK - synced project config cache for "+e)}catch(t){Kn&&console.error(t)}},sw=async e=>{try{Kn&&console.log("deleting project config cache for "+e),await xt(e,["cache-delete",e]),Kn&&console.log("OK - deleted project config cache for "+e)}catch(t){Kn&&console.error(t)}};async function aw(e){await Promise.all(e.changes.map(async t=>{if(t.uri.includes("build.ninja")){if(K.extensionConfiguration.cache?.projectConfig?.enable===!0){let n=Rt(t.uri);n!=null&&await uy(n)}}else if(t.uri.includes("compiler.log"))try{await cy(),ow(),K.extensionConfiguration.inlayHints?.enable===!0&&ly(),K.extensionConfiguration.codeLens===!0&&dy()}catch{console.log("Error while sending updated diagnostics")}else Jm((0,fe.fileURLToPath)(t.uri))}))}var cw=async(e,t)=>{let n=(0,fe.fileURLToPath)(e);Lr.set(n,t);let r=Rt(n);if(r!=null){let i=Te.get(r);if(i==null){K.extensionConfiguration.incrementalTypechecking?.enable&&Ym(r);let u=Fr(r);i={openFiles:new Set,filesWithDiagnostics:new Set,filesDiagnostics:{},namespaceName:u.kind==="success"?u.result:null,rescriptVersion:await $c(r),bsbWatcherByEditor:null,bscBinaryLocation:await Mr(r),editorAnalysisLocation:await Mm(r),hasPromptedToStartBuild:/(\/|\\)node_modules(\/|\\)/.test(r)?"never":!1},Te.set(r,i),K.extensionConfiguration.cache?.projectConfig?.enable===!0&&await uy(r)}Te.get(r).openFiles.add(n);let s=se.join(r,Sp);if(i.hasPromptedToStartBuild===!1&&K.extensionConfiguration.askToStartBuild===!0&&!Ee.default.existsSync(s))if(await ay(r)!=null){let u={title:nc,projectRootPath:r},f={type:O.MessageType.Info,message:"Start a build for this project to get the freshest data?",actions:[u]},m={jsonrpc:G,id:Qo++,method:"window/showMessageRequest",params:f};J(m),i.hasPromptedToStartBuild=!0}else{let u={jsonrpc:G,method:"window/showMessage",params:{type:O.MessageType.Error,message:K.extensionConfiguration.binaryPath==null?`Can't find ReScript binary in ${se.join(r,xp)} or parent directories. Did you install it? It's required to use "rescript" > 9.1`:`Can't find ReScript binary in the directory ${K.extensionConfiguration.binaryPath}`}};J(u)}}},uw=async e=>{let t=(0,fe.fileURLToPath)(e);K.extensionConfiguration.incrementalTypechecking?.enable&&ey(t),Lr.delete(t);let n=Rt(t);if(n!=null){let r=Te.get(n);r!=null&&(r.openFiles.delete(t),r.openFiles.size===0&&(await sw(n),iw(n),r.bsbWatcherByEditor!==null&&(r.bsbWatcherByEditor.kill(),r.bsbWatcherByEditor=null)))}},lw=(e,t)=>{let n=(0,fe.fileURLToPath)(e);(0,Yc.assert)(Lr.has(n)),Lr.set(n,t),K.extensionConfiguration.incrementalTypechecking?.enable&&Km(n,t,J,()=>{K.extensionConfiguration.codeLens&&dy(),K.extensionConfiguration.inlayHints&&ly()})},yn=e=>{let t=(0,fe.fileURLToPath)(e),n=Lr.get(t);return(0,Yc.assert)(n!=null),n};function Zo(e=!1){if(e){let t=new Yo.StreamMessageWriter(mn.default.stdout),n=new Yo.StreamMessageReader(mn.default.stdin);J=r=>t.write(r),n.listen(oy)}else J=t=>mn.default.send(t),mn.default.on("message",oy)}async function dw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=yn(t.textDocument.uri),i=Mt();Ee.default.writeFileSync(i,r,{encoding:"utf-8"});let o=await lt(n,["hover",n,t.position.line,t.position.character,i,!!Jc.supportsMarkdownLinks],e);return Ee.default.unlink(i,()=>null),o}async function fw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri);return await lt(n,["inlayHint",n,t.range.start.line,t.range.end.line,K.extensionConfiguration.inlayHints?.maxLength],e)}function ly(){let e={jsonrpc:G,method:O.InlayHintRefreshRequest.method,id:Qo++};J(e)}async function pw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri);return await lt(n,["codeLens",n],e)}function dy(){let e={jsonrpc:G,method:O.CodeLensRefreshRequest.method,id:Qo++};J(e)}async function hw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=yn(t.textDocument.uri),i=Mt();Ee.default.writeFileSync(i,r,{encoding:"utf-8"});let o=await lt(n,["signatureHelp",n,t.position.line,t.position.character,i,K.extensionConfiguration.signatureHelp?.forConstructorPayloads?"true":"false"],e);return Ee.default.unlink(i,()=>null),o}async function gw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri);return await lt(n,["definition",n,t.position.line,t.position.character],e)}async function mw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri);return await lt(n,["typeDefinition",n,t.position.line,t.position.character],e)}async function yw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=await Wc(n,t.position);return{jsonrpc:G,id:e.id,result:r}}async function vw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=await Wc(n,t.position),i=null;return r!==null&&r.forEach(o=>{if(se.normalize((0,fe.fileURLToPath)(o.uri))===se.normalize((0,fe.fileURLToPath)(t.textDocument.uri))){let{start:s,end:u}=o.range,f=t.position;s.character<=f.character&&s.line<=f.line&&u.character>=f.character&&u.line>=f.line&&(i=o.range)}}),{jsonrpc:G,id:e.id,result:i}}async function bw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=await xt(n,["rename",n,t.position.line,t.position.character,t.newName]),i=null;return r!==null&&(i={documentChanges:r}),{jsonrpc:G,id:e.id,result:i}}async function Rw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=se.extname(t.textDocument.uri),i=yn(t.textDocument.uri),o=Mt(r);Ee.default.writeFileSync(o,i,{encoding:"utf-8"});let s=await lt(n,["documentSymbol",o],e,!1);return Ee.default.unlink(o,()=>null),s}function ry(){let e={items:[{section:"rescript.settings"}]},t={jsonrpc:G,id:rc,method:O.ConfigurationRequest.type.method,params:e};J(t)}async function Dw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=se.extname(t.textDocument.uri),i=yn(t.textDocument.uri),o=Mt(r);Ee.default.writeFileSync(o,i,{encoding:"utf-8"});let s=await lt(n,["semanticTokens",o],e,!1);return Ee.default.unlink(o,()=>null),s}async function _w(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=yn(t.textDocument.uri),i=Mt();Ee.default.writeFileSync(i,r,{encoding:"utf-8"});let o=await lt(n,["completion",n,t.position.line,t.position.character,i],e);return Ee.default.unlink(i,()=>null),o}async function ww(e){let t=e.params,n={jsonrpc:G,id:e.id,result:t};if(t.documentation==null&&t.data!=null){let r=t.data,i=await xt(r.filePath,["completionResolve",r.filePath,r.modulePath],!0);t.documentation={kind:"markdown",value:i}}return n}async function Pw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=yn(t.textDocument.uri),i=se.extname(t.textDocument.uri),o=Mt(i),s=[],u=sy[t.textDocument.uri]??[],f=ty(n)??[];[...u,...f].forEach(({range:P,codeAction:L})=>{Um(P,t.range)&&s.push(L)}),Ee.default.writeFileSync(o,r,{encoding:"utf-8"});let m=await lt(n,["codeAction",n,t.range.start.line,t.range.start.character,t.range.end.line,t.range.end.character,o],e);Ee.default.unlink(o,()=>null);let{result:w}=m,_=w!=null&&Array.isArray(w)?[...s,...w]:s;return{jsonrpc:G,id:e.id,result:_.length>0?_:null}}function Cw(e){let t={jsonrpc:G,id:e.id,result:[]},n=e.params,r=(0,fe.fileURLToPath)(n.textDocument.uri),i=se.extname(n.textDocument.uri);if(i!==Ct&&i!==wr){let o={type:O.MessageType.Error,message:`Not a ${Ct} or ${wr} file. Cannot format it.`};return[t,{jsonrpc:G,method:"window/showMessage",params:o}]}else{let o=yn(n.textDocument.uri),s=Rt(r),f=(s!=null?Te.get(s):null)?.bscBinaryLocation??null,m=$m(f,r,o);if(m.kind==="success"){let w=o.length,_=[{range:{start:{line:0,character:0},end:{line:w,character:w}},newText:m.result}];return[{jsonrpc:G,id:e.id,result:_}]}else return[t]}}var iy=async(e,t)=>{if(K.extensionConfiguration.incrementalTypechecking?.enable)return;let n=(0,fe.fileURLToPath)(e),r=se.extname(n),i=Mt(r);Ee.default.writeFileSync(i,t,{encoding:"utf-8"});let o=rw(e),s=await xt(n,["diagnosticSyntax",i]),u={jsonrpc:G,method:"textDocument/publishDiagnostics",params:{uri:e,diagnostics:[...s,...o]}};Ee.default.unlink(i,()=>null),J(u)};async function Ew(e){let t=e.params,n=se.extname(t.uri),r=(0,fe.fileURLToPath)(t.uri),i=Rt(r);if(i===null){let L={type:O.MessageType.Error,message:"Cannot locate project directory to generate the interface file."};return{jsonrpc:G,method:"window/showMessage",params:L}}if(n!==Ct){let L={type:O.MessageType.Error,message:`Not a ${Ct} file. Cannot create an interface for it.`};return{jsonrpc:G,method:"window/showMessage",params:L}}let o=r.split(i)[1],s=Fr(i);if(s.kind==="error"){let L={type:O.MessageType.Error,message:"Error reading ReScript config file."};return{jsonrpc:G,method:"window/showMessage",params:L}}let u=s.result,f=u.length>0?"-"+u:"",m=se.join(se.dirname(o),se.basename(o,Ct)+f+qp),w=se.join(i,Kt,m);if(!Ee.default.existsSync(w)){let L={type:O.MessageType.Error,message:"No compiled interface file found. Please compile your project first."};return{jsonrpc:G,method:"window/showMessage",params:L}}let T=await lt(r,["createInterface",r,w],e),P=typeof T.result=="string"?T.result:"";try{let L=wo(r,wr);return Ee.default.writeFileSync(L,P,{encoding:"utf-8"}),{jsonrpc:G,id:e.id,result:{uri:Ir(L)}}}catch{return{jsonrpc:G,id:e.id,error:{code:O.ErrorCodes.InternalError,message:"Unable to create interface file."}}}}function xw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.uri),r=Rt(n);if(r===null){let s={type:O.MessageType.Error,message:"Cannot locate project directory."};return{jsonrpc:G,method:"window/showMessage",params:s}}let i=Wm(n,r);if(i.kind==="error"||!Ee.default.existsSync(i.result)){let s=i.kind==="success"?`No compiled file found. Expected it at: ${i.result}`:"No compiled file found. Please compile your project first.",u={type:O.MessageType.Error,message:s};return{jsonrpc:G,method:"window/showMessage",params:u}}return{jsonrpc:G,id:e.id,result:{uri:Ir(i.result)}}}async function oy(e){if(O.Message.isNotification(e)){if(!(!Gc&&e.method!=="exit"))if(e.method==="exit")Xc?mn.default.exit(0):mn.default.exit(1);else if(e.method===tt.InitializedNotification.method){let t=Array.from(ny).flatMap(i=>[{globPattern:se.join(i,"**",ec),kind:O.WatchKind.Change|O.WatchKind.Create|O.WatchKind.Delete},{globPattern:se.join(i,"**",Do),kind:O.WatchKind.Change|O.WatchKind.Create|O.WatchKind.Delete},{globPattern:`${se.join(i,"**",Kt)}/**/*.{cmt,cmi}`,kind:O.WatchKind.Change|O.WatchKind.Delete}]),n={registrations:[{id:"rescript_file_watcher",method:tt.DidChangeWatchedFilesNotification.method,registerOptions:{watchers:t}}]},r={jsonrpc:G,id:Qo++,method:O.RegistrationRequest.method,params:n};J(r)}else if(e.method===tt.DidChangeWatchedFilesNotification.method){let t=e.params;await aw(t)}else if(e.method===tt.DidOpenTextDocumentNotification.method){let t=e.params;await cw(t.textDocument.uri,t.textDocument.text),await cy(),await iy(t.textDocument.uri,t.textDocument.text)}else if(e.method===tt.DidChangeTextDocumentNotification.method){let t=e.params,n=se.extname(t.textDocument.uri);if(n===Ct||n===wr){let r=t.contentChanges;r.length===0||(lw(t.textDocument.uri,r[r.length-1].text),await iy(t.textDocument.uri,r[r.length-1].text))}}else if(e.method===tt.DidCloseTextDocumentNotification.method){let t=e.params;await uw(t.textDocument.uri)}else e.method===tt.DidChangeConfigurationNotification.type.method&&ry()}else if(O.Message.isRequest(e))if(!Gc&&e.method!=="initialize"){let t={jsonrpc:G,id:e.id,error:{code:O.ErrorCodes.ServerNotInitialized,message:"Server not initialized."}};J(t)}else if(e.method==="initialize"){let t=e.params;for(let s of t.workspaceFolders||[]){let u=(0,fe.fileURLToPath)(s.uri);ny.add(u)}let n=t.initializationOptions?.extensionConfiguration;n!=null&&(K.extensionConfiguration=n);let r=t.initializationOptions?.extensionClientCapabilities;r!=null&&(Jc=r),Jc.supportsSnippetSyntax=!!t.capabilities.textDocument?.completion?.completionItem?.snippetSupport;let i={capabilities:{textDocumentSync:$r.TextDocumentSyncKind.Full,documentFormattingProvider:!0,hoverProvider:!0,definitionProvider:!0,typeDefinitionProvider:!0,referencesProvider:!0,codeActionProvider:!0,renameProvider:{prepareProvider:!0},documentSymbolProvider:!0,completionProvider:{triggerCharacters:[".",">","@","~",'"',"=","("],resolveProvider:!0},semanticTokensProvider:{legend:{tokenTypes:["operator","variable","type","modifier","namespace","enumMember","property","interface"],tokenModifiers:[]},documentSelector:[{scheme:"file",language:"rescript"}],full:!0},inlayHintProvider:K.extensionConfiguration.inlayHints?.enable,codeLensProvider:K.extensionConfiguration.codeLens?{workDoneProgress:!1}:void 0,signatureHelpProvider:K.extensionConfiguration.signatureHelp?.enabled?{triggerCharacters:["("],retriggerCharacters:["=",","]}:void 0}},o={jsonrpc:G,id:e.id,result:i};Gc=!0,zc=setInterval(()=>{ry()},Ap),J(o)}else if(e.method==="initialized"){let t={jsonrpc:G,id:e.id,result:null};J(t)}else if(e.method==="shutdown")if(Xc){let t={jsonrpc:G,id:e.id,error:{code:O.ErrorCodes.InvalidRequest,message:"Language server already received the shutdown request"}};J(t)}else{Xc=!0,zc!=null&&clearInterval(zc);let t={jsonrpc:G,id:e.id,result:null};J(t)}else if(e.method===O.HoverRequest.method)J(await dw(e));else if(e.method===O.DefinitionRequest.method)J(await gw(e));else if(e.method===O.TypeDefinitionRequest.method)J(await mw(e));else if(e.method===O.ReferencesRequest.method)J(await yw(e));else if(e.method===O.PrepareRenameRequest.method)J(await vw(e));else if(e.method===O.RenameRequest.method)J(await bw(e));else if(e.method===O.DocumentSymbolRequest.method)J(await Rw(e));else if(e.method===O.CompletionRequest.method)J(await _w(e));else if(e.method===O.CompletionResolveRequest.method)J(await ww(e));else if(e.method===O.SemanticTokensRequest.method)J(await Dw(e));else if(e.method===O.CodeActionRequest.method)J(await Pw(e));else if(e.method===O.DocumentFormattingRequest.method)Cw(e).forEach(n=>J(n));else if(e.method===tw.method)J(await Ew(e));else if(e.method===nw.method)J(xw(e));else if(e.method===O.InlayHintRequest.method){let t=e.params;se.extname(t.textDocument.uri)===Ct&&J(await fw(e))}else if(e.method===O.CodeLensRequest.method){let t=e.params;se.extname(t.textDocument.uri)===Ct&&J(await pw(e))}else if(e.method===O.SignatureHelpRequest.method){let t=e.params;se.extname(t.textDocument.uri)===Ct&&J(await hw(e))}else{let t={jsonrpc:G,id:e.id,error:{code:O.ErrorCodes.InvalidRequest,message:"Unrecognized editor request."}};J(t)}else if(O.Message.isResponse(e)){if(e.id===rc){if(e.result!=null){let[t]=e.result;t!=null&&(K.extensionConfiguration=t)}}else if(e.result!=null&&e.result.title!=null&&e.result.title===nc){let n=e.result.projectRootPath,r=await ay(n);if(r!=null){let i=Hm(r,n),o=Te.get(n);o.bsbWatcherByEditor=i}}}}qm(e=>{let t={type:O.MessageType.Warning,message:`ReScript tooling: Internal error. Something broke. Here's the error message that you can report if you want:
|
|
46
|
+
${_}`);let v={type:Gm.MessageType.Warning,message:`[Incremental typechecking] Something might have gone wrong with incremental type checking. Check out the [error log](file://${y}) and report this issue please.`};n({jsonrpc:G,method:"window/showMessage",params:v})}catch(y){console.error(y)}let H={jsonrpc:G,method:"textDocument/publishDiagnostics",params:{uri:(0,Hc.pathToFileURL)(e.file.sourceFilePath),diagnostics:re}};n(H)}r?.()});e.killCompilationListeners.push(()=>{f.kill("SIGKILL")})}catch(u){console.error(u)}}function Km(e,t,n,r){Ne()&&console.log("Updated: "+e),Q_(e,t,n,r)}function ey(e){Ne()&&console.log("Closed: "+e);let t=gn.get(e);t!=null&&(Qm(e,t.project.rootPath),gn.delete(e),Vc.delete(t.file.originalTypeFileLocation))}function ty(e){let t=gn.get(e);return t!=null?t.codeActions:null}var ny=new Set,Jc={},zc=null,Gc=!1,Qo=0,Xc=!1,Lr=new Map,sy={},J=e=>{},ay=async e=>K.extensionConfiguration.binaryPath!=null&&Ee.default.existsSync(se.join(K.extensionConfiguration.binaryPath,"rescript"))?se.join(K.extensionConfiguration.binaryPath,"rescript"):Om(e),tw=new $r.RequestType("textDocument/createInterface"),nw=new $r.RequestType("textDocument/openCompiled"),rw=e=>{let t=null;return Te.forEach((n,r)=>{t==null&&n.filesDiagnostics[e]!=null&&(t=n.filesDiagnostics[e].slice())}),t??[]},cy=async()=>{for(let[e,t]of Te){let{filesWithDiagnostics:n}=t,r=se.join(e,ec),i="";try{i=Ee.default.readFileSync(r,{encoding:"utf-8"})}catch(m){console.error(`Error reading compiler log file ${r}: ${m}`)}let{done:o,result:s,codeActions:u,linesWithParseErrors:f}=await Go(i);if(f.length>0){let m={type:O.MessageType.Warning,message:`There are more compiler warning/errors that we could not parse. You can help us fix this by opening an [issue on the repository](https://github.com/rescript-lang/rescript-vscode/issues/new?title=Compiler%20log%20parse%20error), pasting the contents of the file [lib/bs/.compiler.log](file://${r}).`};J({jsonrpc:G,method:"window/showMessage",params:m})}t.filesDiagnostics=s,sy=u,Object.keys(s).forEach(m=>{let w={uri:m,diagnostics:s[m]};J({jsonrpc:G,method:"textDocument/publishDiagnostics",params:w}),n.add(m)}),o&&n.forEach(m=>{s[m]==null&&(J({jsonrpc:G,method:"textDocument/publishDiagnostics",params:{uri:m,diagnostics:[]}}),n.delete(m))})}},iw=e=>{let t=Te.get(e);t!=null&&(t.filesWithDiagnostics.forEach(n=>{J({jsonrpc:G,method:"textDocument/publishDiagnostics",params:{uri:n,diagnostics:[]}})}),Te.delete(e),K.extensionConfiguration.incrementalTypechecking?.enable&&Bc(e))},ow=()=>{J({jsonrpc:G,method:"rescript/compilationFinished"})},Kn=!1,uy=async e=>{try{Kn&&console.log("syncing project config cache for "+e),await xt(e,["cache-project",e]),Kn&&console.log("OK - synced project config cache for "+e)}catch(t){Kn&&console.error(t)}},sw=async e=>{try{Kn&&console.log("deleting project config cache for "+e),await xt(e,["cache-delete",e]),Kn&&console.log("OK - deleted project config cache for "+e)}catch(t){Kn&&console.error(t)}};async function aw(e){await Promise.all(e.changes.map(async t=>{if(t.uri.includes("build.ninja")){if(K.extensionConfiguration.cache?.projectConfig?.enable===!0){let n=Rt(t.uri);n!=null&&await uy(n)}}else if(t.uri.includes("compiler.log"))try{await cy(),ow(),K.extensionConfiguration.inlayHints?.enable===!0&&ly(),K.extensionConfiguration.codeLens===!0&&dy()}catch{console.log("Error while sending updated diagnostics")}else Jm((0,fe.fileURLToPath)(t.uri))}))}var cw=async(e,t)=>{let n=(0,fe.fileURLToPath)(e);Lr.set(n,t);let r=Rt(n);if(r!=null){let i=Te.get(r);if(i==null){K.extensionConfiguration.incrementalTypechecking?.enable&&Ym(r);let u=Fr(r);i={openFiles:new Set,filesWithDiagnostics:new Set,filesDiagnostics:{},namespaceName:u.kind==="success"?u.result:null,rescriptVersion:await $c(r),bsbWatcherByEditor:null,bscBinaryLocation:await Mr(r),editorAnalysisLocation:await Mm(r),hasPromptedToStartBuild:/(\/|\\)node_modules(\/|\\)/.test(r)?"never":!1},Te.set(r,i),K.extensionConfiguration.cache?.projectConfig?.enable===!0&&await uy(r)}Te.get(r).openFiles.add(n);let s=se.join(r,Sp);if(i.hasPromptedToStartBuild===!1&&K.extensionConfiguration.askToStartBuild===!0&&!Ee.default.existsSync(s))if(await ay(r)!=null){let u={title:nc,projectRootPath:r},f={type:O.MessageType.Info,message:"Start a build for this project to get the freshest data?",actions:[u]},m={jsonrpc:G,id:Qo++,method:"window/showMessageRequest",params:f};J(m),i.hasPromptedToStartBuild=!0}else{let u={jsonrpc:G,method:"window/showMessage",params:{type:O.MessageType.Error,message:K.extensionConfiguration.binaryPath==null?`Can't find ReScript binary in ${se.join(r,xp)} or parent directories. Did you install it? It's required to use "rescript" > 9.1`:`Can't find ReScript binary in the directory ${K.extensionConfiguration.binaryPath}`}};J(u)}}},uw=async e=>{let t=(0,fe.fileURLToPath)(e);K.extensionConfiguration.incrementalTypechecking?.enable&&ey(t),Lr.delete(t);let n=Rt(t);if(n!=null){let r=Te.get(n);r!=null&&(r.openFiles.delete(t),r.openFiles.size===0&&(await sw(n),iw(n),r.bsbWatcherByEditor!==null&&(r.bsbWatcherByEditor.kill(),r.bsbWatcherByEditor=null)))}},lw=(e,t)=>{let n=(0,fe.fileURLToPath)(e);(0,Yc.assert)(Lr.has(n)),Lr.set(n,t),K.extensionConfiguration.incrementalTypechecking?.enable&&Km(n,t,J,()=>{K.extensionConfiguration.codeLens&&dy(),K.extensionConfiguration.inlayHints&&ly()})},yn=e=>{let t=(0,fe.fileURLToPath)(e),n=Lr.get(t);return(0,Yc.assert)(n!=null),n};function Zo(e=!1){if(e){let t=new Yo.StreamMessageWriter(mn.default.stdout),n=new Yo.StreamMessageReader(mn.default.stdin);J=r=>t.write(r),n.listen(oy)}else J=t=>mn.default.send(t),mn.default.on("message",oy)}async function dw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=yn(t.textDocument.uri),i=Mt();Ee.default.writeFileSync(i,r,{encoding:"utf-8"});let o=await lt(n,["hover",n,t.position.line,t.position.character,i,!!Jc.supportsMarkdownLinks],e);return Ee.default.unlink(i,()=>null),o}async function fw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri);return await lt(n,["inlayHint",n,t.range.start.line,t.range.end.line,K.extensionConfiguration.inlayHints?.maxLength],e)}function ly(){let e={jsonrpc:G,method:O.InlayHintRefreshRequest.method,id:Qo++};J(e)}async function pw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri);return await lt(n,["codeLens",n],e)}function dy(){let e={jsonrpc:G,method:O.CodeLensRefreshRequest.method,id:Qo++};J(e)}async function hw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=yn(t.textDocument.uri),i=Mt();Ee.default.writeFileSync(i,r,{encoding:"utf-8"});let o=await lt(n,["signatureHelp",n,t.position.line,t.position.character,i,K.extensionConfiguration.signatureHelp?.forConstructorPayloads?"true":"false"],e);return Ee.default.unlink(i,()=>null),o}async function gw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri);return await lt(n,["definition",n,t.position.line,t.position.character],e)}async function mw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri);return await lt(n,["typeDefinition",n,t.position.line,t.position.character],e)}async function yw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=await Wc(n,t.position);return{jsonrpc:G,id:e.id,result:r}}async function vw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=await Wc(n,t.position),i=null;return r!==null&&r.forEach(o=>{if(se.normalize((0,fe.fileURLToPath)(o.uri))===se.normalize((0,fe.fileURLToPath)(t.textDocument.uri))){let{start:s,end:u}=o.range,f=t.position;s.character<=f.character&&s.line<=f.line&&u.character>=f.character&&u.line>=f.line&&(i=o.range)}}),{jsonrpc:G,id:e.id,result:i}}async function bw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=await xt(n,["rename",n,t.position.line,t.position.character,t.newName]),i=null;return r!==null&&(i={documentChanges:r}),{jsonrpc:G,id:e.id,result:i}}async function Rw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=se.extname(t.textDocument.uri),i=yn(t.textDocument.uri),o=Mt(r);Ee.default.writeFileSync(o,i,{encoding:"utf-8"});let s=await lt(n,["documentSymbol",o],e,!1);return Ee.default.unlink(o,()=>null),s}function ry(){let e={items:[{section:"rescript.settings"}]},t={jsonrpc:G,id:rc,method:O.ConfigurationRequest.type.method,params:e};J(t)}async function Dw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=se.extname(t.textDocument.uri),i=yn(t.textDocument.uri),o=Mt(r);Ee.default.writeFileSync(o,i,{encoding:"utf-8"});let s=await lt(n,["semanticTokens",o],e,!1);return Ee.default.unlink(o,()=>null),s}async function _w(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=yn(t.textDocument.uri),i=Mt();Ee.default.writeFileSync(i,r,{encoding:"utf-8"});let o=await lt(n,["completion",n,t.position.line,t.position.character,i],e);return Ee.default.unlink(i,()=>null),o}async function ww(e){let t=e.params,n={jsonrpc:G,id:e.id,result:t};if(t.documentation==null&&t.data!=null){let r=t.data,i=await xt(r.filePath,["completionResolve",r.filePath,r.modulePath],!0);t.documentation={kind:"markdown",value:i}}return n}async function Pw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=yn(t.textDocument.uri),i=se.extname(t.textDocument.uri),o=Mt(i),s=[],u=sy[t.textDocument.uri]??[],f=ty(n)??[];[...u,...f].forEach(({range:P,codeAction:L})=>{Um(P,t.range)&&s.push(L)}),Ee.default.writeFileSync(o,r,{encoding:"utf-8"});let m=await lt(n,["codeAction",n,t.range.start.line,t.range.start.character,t.range.end.line,t.range.end.character,o],e);Ee.default.unlink(o,()=>null);let{result:w}=m,_=w!=null&&Array.isArray(w)?[...s,...w]:s;return{jsonrpc:G,id:e.id,result:_.length>0?_:null}}function Cw(e){let t={jsonrpc:G,id:e.id,result:[]},n=e.params,r=(0,fe.fileURLToPath)(n.textDocument.uri),i=se.extname(n.textDocument.uri);if(i!==Ct&&i!==wr){let o={type:O.MessageType.Error,message:`Not a ${Ct} or ${wr} file. Cannot format it.`};return[t,{jsonrpc:G,method:"window/showMessage",params:o}]}else{let o=yn(n.textDocument.uri),s=Rt(r),f=(s!=null?Te.get(s):null)?.bscBinaryLocation??null,m=$m(f,r,o);if(m.kind==="success"){let w=o.length,_=[{range:{start:{line:0,character:0},end:{line:w,character:w}},newText:m.result}];return[{jsonrpc:G,id:e.id,result:_}]}else return[t]}}var iy=async(e,t)=>{if(K.extensionConfiguration.incrementalTypechecking?.enable)return;let n=(0,fe.fileURLToPath)(e),r=se.extname(n),i=Mt(r);Ee.default.writeFileSync(i,t,{encoding:"utf-8"});let o=rw(e),s=await xt(n,["diagnosticSyntax",i]),u={jsonrpc:G,method:"textDocument/publishDiagnostics",params:{uri:e,diagnostics:[...s,...o]}};Ee.default.unlink(i,()=>null),J(u)};async function Ew(e){let t=e.params,n=se.extname(t.uri),r=(0,fe.fileURLToPath)(t.uri),i=Rt(r);if(i===null){let L={type:O.MessageType.Error,message:"Cannot locate project directory to generate the interface file."};return{jsonrpc:G,method:"window/showMessage",params:L}}if(n!==Ct){let L={type:O.MessageType.Error,message:`Not a ${Ct} file. Cannot create an interface for it.`};return{jsonrpc:G,method:"window/showMessage",params:L}}let o=r.split(i)[1],s=Fr(i);if(s.kind==="error"){let L={type:O.MessageType.Error,message:"Error reading ReScript config file."};return{jsonrpc:G,method:"window/showMessage",params:L}}let u=s.result,f=u.length>0?"-"+u:"",m=se.join(se.dirname(o),se.basename(o,Ct)+f+qp),w=se.join(i,Kt,m);if(!Ee.default.existsSync(w)){let L={type:O.MessageType.Error,message:"No compiled interface file found. Please compile your project first."};return{jsonrpc:G,method:"window/showMessage",params:L}}let T=await lt(r,["createInterface",r,w],e),P=typeof T.result=="string"?T.result:"";try{let L=wo(r,wr);return Ee.default.writeFileSync(L,P,{encoding:"utf-8"}),{jsonrpc:G,id:e.id,result:{uri:Ir(L)}}}catch{return{jsonrpc:G,id:e.id,error:{code:O.ErrorCodes.InternalError,message:"Unable to create interface file."}}}}function xw(e){let t=e.params,n=(0,fe.fileURLToPath)(t.uri),r=Rt(n);if(r===null){let s={type:O.MessageType.Error,message:"Cannot locate project directory."};return{jsonrpc:G,method:"window/showMessage",params:s}}let i=Wm(n,r);if(i.kind==="error"||!Ee.default.existsSync(i.result)){let s=i.kind==="success"?`No compiled file found. Expected it at: ${i.result}`:"No compiled file found. Please compile your project first.",u={type:O.MessageType.Error,message:s};return{jsonrpc:G,method:"window/showMessage",params:u}}return{jsonrpc:G,id:e.id,result:{uri:Ir(i.result)}}}async function oy(e){if(O.Message.isNotification(e)){if(!(!Gc&&e.method!=="exit"))if(e.method==="exit")Xc?mn.default.exit(0):mn.default.exit(1);else if(e.method===tt.InitializedNotification.method){let t=Array.from(ny).flatMap(i=>[{globPattern:se.join(i,"**",ec),kind:O.WatchKind.Change|O.WatchKind.Create|O.WatchKind.Delete},{globPattern:se.join(i,"**",Do),kind:O.WatchKind.Change|O.WatchKind.Create|O.WatchKind.Delete},{globPattern:`${se.join(i,"**",Kt)}/**/*.{cmt,cmi}`,kind:O.WatchKind.Change|O.WatchKind.Delete}]),n={registrations:[{id:"rescript_file_watcher",method:tt.DidChangeWatchedFilesNotification.method,registerOptions:{watchers:t}}]},r={jsonrpc:G,id:Qo++,method:O.RegistrationRequest.method,params:n};J(r)}else if(e.method===tt.DidChangeWatchedFilesNotification.method){let t=e.params;await aw(t)}else if(e.method===tt.DidOpenTextDocumentNotification.method){let t=e.params;await cw(t.textDocument.uri,t.textDocument.text),await cy(),await iy(t.textDocument.uri,t.textDocument.text)}else if(e.method===tt.DidChangeTextDocumentNotification.method){let t=e.params,n=se.extname(t.textDocument.uri);if(n===Ct||n===wr){let r=t.contentChanges;r.length===0||(lw(t.textDocument.uri,r[r.length-1].text),await iy(t.textDocument.uri,r[r.length-1].text))}}else if(e.method===tt.DidCloseTextDocumentNotification.method){let t=e.params;await uw(t.textDocument.uri)}else e.method===tt.DidChangeConfigurationNotification.type.method&&ry()}else if(O.Message.isRequest(e))if(!Gc&&e.method!=="initialize"){let t={jsonrpc:G,id:e.id,error:{code:O.ErrorCodes.ServerNotInitialized,message:"Server not initialized."}};J(t)}else if(e.method==="initialize"){let t=e.params;for(let s of t.workspaceFolders||[]){let u=(0,fe.fileURLToPath)(s.uri);ny.add(u)}let n=t.initializationOptions?.extensionConfiguration;n!=null&&(K.extensionConfiguration=n);let r=t.initializationOptions?.extensionClientCapabilities;r!=null&&(Jc=r),Jc.supportsSnippetSyntax=!!t.capabilities.textDocument?.completion?.completionItem?.snippetSupport;let i={capabilities:{textDocumentSync:$r.TextDocumentSyncKind.Full,documentFormattingProvider:!0,hoverProvider:!0,definitionProvider:!0,typeDefinitionProvider:!0,referencesProvider:!0,codeActionProvider:!0,renameProvider:{prepareProvider:!0},documentSymbolProvider:!0,completionProvider:{triggerCharacters:[".",">","@","~",'"',"=","("],resolveProvider:!0},semanticTokensProvider:{legend:{tokenTypes:["operator","variable","type","modifier","namespace","enumMember","property","interface"],tokenModifiers:[]},documentSelector:[{scheme:"file",language:"rescript"}],full:!0},inlayHintProvider:K.extensionConfiguration.inlayHints?.enable,codeLensProvider:K.extensionConfiguration.codeLens?{workDoneProgress:!1}:void 0,signatureHelpProvider:K.extensionConfiguration.signatureHelp?.enabled?{triggerCharacters:["("],retriggerCharacters:["=",","]}:void 0}},o={jsonrpc:G,id:e.id,result:i};Gc=!0,zc=setInterval(()=>{ry()},Ap),J(o)}else if(e.method==="initialized"){let t={jsonrpc:G,id:e.id,result:null};J(t)}else if(e.method==="shutdown")if(Xc){let t={jsonrpc:G,id:e.id,error:{code:O.ErrorCodes.InvalidRequest,message:"Language server already received the shutdown request"}};J(t)}else{Xc=!0,zc!=null&&clearInterval(zc);let t={jsonrpc:G,id:e.id,result:null};J(t)}else if(e.method===O.HoverRequest.method)J(await dw(e));else if(e.method===O.DefinitionRequest.method)J(await gw(e));else if(e.method===O.TypeDefinitionRequest.method)J(await mw(e));else if(e.method===O.ReferencesRequest.method)J(await yw(e));else if(e.method===O.PrepareRenameRequest.method)J(await vw(e));else if(e.method===O.RenameRequest.method)J(await bw(e));else if(e.method===O.DocumentSymbolRequest.method)J(await Rw(e));else if(e.method===O.CompletionRequest.method)J(await _w(e));else if(e.method===O.CompletionResolveRequest.method)J(await ww(e));else if(e.method===O.SemanticTokensRequest.method)J(await Dw(e));else if(e.method===O.CodeActionRequest.method)J(await Pw(e));else if(e.method===O.DocumentFormattingRequest.method)Cw(e).forEach(n=>J(n));else if(e.method===tw.method)J(await Ew(e));else if(e.method===nw.method)J(xw(e));else if(e.method===O.InlayHintRequest.method){let t=e.params;se.extname(t.textDocument.uri)===Ct&&J(await fw(e))}else if(e.method===O.CodeLensRequest.method){let t=e.params;se.extname(t.textDocument.uri)===Ct&&J(await pw(e))}else if(e.method===O.SignatureHelpRequest.method){let t=e.params;se.extname(t.textDocument.uri)===Ct&&J(await hw(e))}else{let t={jsonrpc:G,id:e.id,error:{code:O.ErrorCodes.InvalidRequest,message:"Unrecognized editor request."}};J(t)}else if(O.Message.isResponse(e)){if(e.id===rc){if(e.result!=null){let[t]=e.result;t!=null&&(K.extensionConfiguration=t)}}else if(e.result!=null&&e.result.title!=null&&e.result.title===nc){let n=e.result.projectRootPath,r=await ay(n);if(r!=null){let i=Hm(r,n),o=Te.get(n);o.bsbWatcherByEditor=i}}}}qm(e=>{let t={type:O.MessageType.Warning,message:`ReScript tooling: Internal error. Something broke. Here's the error message that you can report if you want:
|
|
47
47
|
|
|
48
48
|
${e}
|
|
49
49
|
|