@rescript/language-server 1.63.0-next-42cdfd3.0 → 1.63.0-next-9f58cea.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/out/cli.js CHANGED
@@ -43,7 +43,7 @@ ${o}`)},console.warn=function(...i){e.warn(t(i))}}});var xr=x((sC,Mh)=>{"use str
43
43
  ${o?.join(" ")}
44
44
 
45
45
  == OUTPUT ==
46
- ${D}`);let _={type:Vm.MessageType.Warning,message:`[Incremental typechecking] Something might have gone wrong with incremental type checking. Check out the [error log](file://${L}) and report this issue please.`};n({jsonrpc:G,method:"window/showMessage",params:_})}catch(L){console.error(L)}let K={jsonrpc:G,method:"textDocument/publishDiagnostics",params:{uri:(0,Wc.pathToFileURL)(e.file.sourceFilePath),diagnostics:H}};n(K)}r?.()});e.killCompilationListeners.push(()=>{u.kill("SIGKILL")})}catch(u){console.error(u)}}function Ym(e,t,n,r){Je()&&console.log("Updated: "+e),G_(e,t,n,r)}function Qm(e){Je()&&console.log("Closed: "+e);let t=hn.get(e);t!=null&&(Xm(e,t.project.rootPath),hn.delete(e),Vc.delete(t.file.originalTypeFileLocation))}function Zm(e){let t=hn.get(e);return t!=null?t.codeActions:null}var Km=new Set,Jc={},zc=null,Gc=!1,Xo=0,Xc=!1,Or=new Map,ry={},J=e=>{},iy=async e=>ee.extensionConfiguration.binaryPath!=null&&Ee.default.existsSync(oe.join(ee.extensionConfiguration.binaryPath,"rescript"))?oe.join(ee.extensionConfiguration.binaryPath,"rescript"):Im(e),Q_=new Mr.RequestType("textDocument/createInterface"),Z_=new Mr.RequestType("textDocument/openCompiled"),K_=e=>{let t=null;return Te.forEach((n,r)=>{t==null&&n.filesDiagnostics[e]!=null&&(t=n.filesDiagnostics[e].slice())}),t??[]},eP=async()=>{for(let[e,t]of Te){let{filesWithDiagnostics:n}=t,r=oe.join(e,Qa),i=Ee.default.readFileSync(r,{encoding:"utf-8"}),{done:o,result:s,codeActions:u,linesWithParseErrors:f}=await Vo(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,ry=u,Object.keys(s).forEach(m=>{let D={uri:m,diagnostics:s[m]};J({jsonrpc:G,method:"textDocument/publishDiagnostics",params:D}),n.add(m)}),o&&n.forEach(m=>{s[m]==null&&(J({jsonrpc:G,method:"textDocument/publishDiagnostics",params:{uri:m,diagnostics:[]}}),n.delete(m))})}},tP=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),ee.extensionConfiguration.incrementalTypechecking?.enable&&Bc(e))},nP=()=>{J({jsonrpc:G,method:"rescript/compilationFinished"})},Zn=!1,oy=async e=>{try{Zn&&console.log("syncing project config cache for "+e),await xt(e,["cache-project",e]),Zn&&console.log("OK - synced project config cache for "+e)}catch(t){Zn&&console.error(t)}},rP=async e=>{try{Zn&&console.log("deleting project config cache for "+e),await xt(e,["cache-delete",e]),Zn&&console.log("OK - deleted project config cache for "+e)}catch(t){Zn&&console.error(t)}};async function iP(e){await Promise.all(e.changes.map(async t=>{if(t.uri.includes("build.ninja")){if(ee.extensionConfiguration.cache?.projectConfig?.enable===!0){let n=Rt(t.uri);n!=null&&await oy(n)}}else if(t.uri.includes("compiler.log"))try{await eP(),nP(),ee.extensionConfiguration.inlayHints?.enable===!0&&sy(),ee.extensionConfiguration.codeLens===!0&&ay()}catch{console.log("Error while sending updated diagnostics")}else zm((0,fe.fileURLToPath)(t.uri))}))}var oP=async(e,t)=>{let n=(0,fe.fileURLToPath)(e);Or.set(n,t);let r=Rt(n);if(r!=null){let i=Te.get(r);if(i==null){ee.extensionConfiguration.incrementalTypechecking?.enable&&Gm(r);let u=Ir(r);i={openFiles:new Set,filesWithDiagnostics:new Set,filesDiagnostics:{},namespaceName:u.kind==="success"?u.result:null,rescriptVersion:await Lc(r),bsbWatcherByEditor:null,bscBinaryLocation:await Fc(r),editorAnalysisLocation:await Om(r),hasPromptedToStartBuild:/(\/|\\)node_modules(\/|\\)/.test(r)?"never":!1},Te.set(r,i),ee.extensionConfiguration.cache?.projectConfig?.enable===!0&&await oy(r)}Te.get(r).openFiles.add(n);let s=oe.join(r,Sp);if(i.hasPromptedToStartBuild===!1&&ee.extensionConfiguration.askToStartBuild===!0&&!Ee.default.existsSync(s))if(await iy(r)!=null){let u={title:Ka,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:Xo++,method:"window/showMessageRequest",params:f};J(m),i.hasPromptedToStartBuild=!0}else{let u={jsonrpc:G,method:"window/showMessage",params:{type:O.MessageType.Error,message:ee.extensionConfiguration.binaryPath==null?`Can't find ReScript binary in ${oe.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 ${ee.extensionConfiguration.binaryPath}`}};J(u)}}},sP=async e=>{let t=(0,fe.fileURLToPath)(e);ee.extensionConfiguration.incrementalTypechecking?.enable&&Qm(t),Or.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 rP(n),tP(n),r.bsbWatcherByEditor!==null&&(r.bsbWatcherByEditor.kill(),r.bsbWatcherByEditor=null)))}},aP=(e,t)=>{let n=(0,fe.fileURLToPath)(e);(0,Yc.assert)(Or.has(n)),Or.set(n,t),ee.extensionConfiguration.incrementalTypechecking?.enable&&Ym(n,t,J,()=>{ee.extensionConfiguration.codeLens&&ay(),ee.extensionConfiguration.inlayHints&&sy()})},mn=e=>{let t=(0,fe.fileURLToPath)(e),n=Or.get(t);return(0,Yc.assert)(n!=null),n};function Jo(e=!1){if(e){let t=new Go.StreamMessageWriter(gn.default.stdout),n=new Go.StreamMessageReader(gn.default.stdin);J=r=>t.write(r),n.listen(ny)}else J=t=>gn.default.send(t),gn.default.on("message",ny)}async function cP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=mn(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 uP(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,ee.extensionConfiguration.inlayHints?.maxLength],e)}function sy(){let e={jsonrpc:G,method:O.InlayHintRefreshRequest.method,id:Xo++};J(e)}async function lP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri);return await lt(n,["codeLens",n],e)}function ay(){let e={jsonrpc:G,method:O.CodeLensRefreshRequest.method,id:Xo++};J(e)}async function dP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=mn(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,ee.extensionConfiguration.signatureHelp?.forConstructorPayloads?"true":"false"],e);return Ee.default.unlink(i,()=>null),o}async function fP(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 pP(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 hP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=await $c(n,t.position);return{jsonrpc:G,id:e.id,result:r}}async function gP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=await $c(n,t.position),i=null;return r!==null&&r.forEach(o=>{if(oe.normalize((0,fe.fileURLToPath)(o.uri))===oe.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 mP(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 yP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=oe.extname(t.textDocument.uri),i=mn(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 ey(){let e={items:[{section:"rescript.settings"}]},t={jsonrpc:G,id:ec,method:O.ConfigurationRequest.type.method,params:e};J(t)}async function vP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=oe.extname(t.textDocument.uri),i=mn(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 bP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=mn(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 RP(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 DP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=mn(t.textDocument.uri),i=oe.extname(t.textDocument.uri),o=Mt(i),s=[],u=ry[t.textDocument.uri]??[],f=Zm(n)??[];[...u,...f].forEach(({range:C,codeAction:$})=>{$m(C,t.range)&&s.push($)}),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:D}=m,P=D!=null&&Array.isArray(D)?[...s,...D]:s;return{jsonrpc:G,id:e.id,result:P.length>0?P:null}}function _P(e){let t={jsonrpc:G,id:e.id,result:[]},n=e.params,r=(0,fe.fileURLToPath)(n.textDocument.uri),i=oe.extname(n.textDocument.uri);if(i!==Ct&&i!==_r){let o={type:O.MessageType.Error,message:`Not a ${Ct} or ${_r} file. Cannot format it.`};return[t,{jsonrpc:G,method:"window/showMessage",params:o}]}else{let o=mn(n.textDocument.uri),s=Rt(r),f=(s!=null?Te.get(s):null)?.bscBinaryLocation??null,m=Mm(f,r,o);if(m.kind==="success"){let D=o.length,P=[{range:{start:{line:0,character:0},end:{line:D,character:D}},newText:m.result}];return[{jsonrpc:G,id:e.id,result:P}]}else return[t]}}var ty=async(e,t)=>{if(ee.extensionConfiguration.incrementalTypechecking?.enable)return;let n=(0,fe.fileURLToPath)(e),r=oe.extname(n),i=Mt(r);Ee.default.writeFileSync(i,t,{encoding:"utf-8"});let o=K_(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 PP(e){let t=e.params,n=oe.extname(t.uri),r=(0,fe.fileURLToPath)(t.uri),i=Rt(r);if(i===null){let $={type:O.MessageType.Error,message:"Cannot locate project directory to generate the interface file."};return{jsonrpc:G,method:"window/showMessage",params:$}}if(n!==Ct){let $={type:O.MessageType.Error,message:`Not a ${Ct} file. Cannot create an interface for it.`};return{jsonrpc:G,method:"window/showMessage",params:$}}let o=r.split(i)[1],s=Ir(i);if(s.kind==="error"){let $={type:O.MessageType.Error,message:"Error reading ReScript config file."};return{jsonrpc:G,method:"window/showMessage",params:$}}let u=s.result,f=u.length>0?"-"+u:"",m=oe.join(oe.dirname(o),oe.basename(o,Ct)+f+qp),D=oe.join(i,fn,m);if(!Ee.default.existsSync(D)){let $={type:O.MessageType.Error,message:"No compiled interface file found. Please compile your project first."};return{jsonrpc:G,method:"window/showMessage",params:$}}let T=await lt(r,["createInterface",r,D],e),C=typeof T.result=="string"?T.result:"";try{let $=Ro(r,_r);return Ee.default.writeFileSync($,C,{encoding:"utf-8"}),{jsonrpc:G,id:e.id,result:{uri:Ar($)}}}catch{return{jsonrpc:G,id:e.id,error:{code:O.ErrorCodes.InternalError,message:"Unable to create interface file."}}}}function wP(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=Fm(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:Ar(i.result)}}}async function ny(e){if(O.Message.isNotification(e)){if(!(!Gc&&e.method!=="exit"))if(e.method==="exit")Xc?gn.default.exit(0):gn.default.exit(1);else if(e.method===et.InitializedNotification.method){let t=Array.from(Km).flatMap(i=>[{globPattern:oe.join(i,Qa),kind:O.WatchKind.Change|O.WatchKind.Create|O.WatchKind.Delete},{globPattern:oe.join(i,vo),kind:O.WatchKind.Change|O.WatchKind.Create|O.WatchKind.Delete},{globPattern:`${oe.join(i,fn)}/**/*.{cmt,cmi}`,kind:O.WatchKind.Change|O.WatchKind.Delete}]),n={registrations:[{id:"rescript_file_watcher",method:et.DidChangeWatchedFilesNotification.method,registerOptions:{watchers:t}}]},r={jsonrpc:G,id:Xo++,method:O.RegistrationRequest.method,params:n};J(r)}else if(e.method===et.DidChangeWatchedFilesNotification.method){let t=e.params;await iP(t)}else if(e.method===et.DidOpenTextDocumentNotification.method){let t=e.params;await oP(t.textDocument.uri,t.textDocument.text),await ty(t.textDocument.uri,t.textDocument.text)}else if(e.method===et.DidChangeTextDocumentNotification.method){let t=e.params,n=oe.extname(t.textDocument.uri);if(n===Ct||n===_r){let r=t.contentChanges;r.length===0||(aP(t.textDocument.uri,r[r.length-1].text),await ty(t.textDocument.uri,r[r.length-1].text))}}else if(e.method===et.DidCloseTextDocumentNotification.method){let t=e.params;await sP(t.textDocument.uri)}else e.method===et.DidChangeConfigurationNotification.type.method&&ey()}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);Km.add(u)}let n=t.initializationOptions?.extensionConfiguration;n!=null&&(ee.extensionConfiguration=n);let r=t.initializationOptions?.extensionClientCapabilities;r!=null&&(Jc=r),Jc.supportsSnippetSyntax=!!t.capabilities.textDocument?.completion?.completionItem?.snippetSupport;let i={capabilities:{textDocumentSync:Mr.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:ee.extensionConfiguration.inlayHints?.enable,codeLensProvider:ee.extensionConfiguration.codeLens?{workDoneProgress:!1}:void 0,signatureHelpProvider:ee.extensionConfiguration.signatureHelp?.enabled?{triggerCharacters:["("],retriggerCharacters:["=",","]}:void 0}},o={jsonrpc:G,id:e.id,result:i};Gc=!0,zc=setInterval(()=>{ey()},Np),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 cP(e));else if(e.method===O.DefinitionRequest.method)J(await fP(e));else if(e.method===O.TypeDefinitionRequest.method)J(await pP(e));else if(e.method===O.ReferencesRequest.method)J(await hP(e));else if(e.method===O.PrepareRenameRequest.method)J(await gP(e));else if(e.method===O.RenameRequest.method)J(await mP(e));else if(e.method===O.DocumentSymbolRequest.method)J(await yP(e));else if(e.method===O.CompletionRequest.method)J(await bP(e));else if(e.method===O.CompletionResolveRequest.method)J(await RP(e));else if(e.method===O.SemanticTokensRequest.method)J(await vP(e));else if(e.method===O.CodeActionRequest.method)J(await DP(e));else if(e.method===O.DocumentFormattingRequest.method)_P(e).forEach(n=>J(n));else if(e.method===Q_.method)J(await PP(e));else if(e.method===Z_.method)J(wP(e));else if(e.method===O.InlayHintRequest.method){let t=e.params;oe.extname(t.textDocument.uri)===Ct&&J(await uP(e))}else if(e.method===O.CodeLensRequest.method){let t=e.params;oe.extname(t.textDocument.uri)===Ct&&J(await lP(e))}else if(e.method===O.SignatureHelpRequest.method){let t=e.params;oe.extname(t.textDocument.uri)===Ct&&J(await dP(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===ec){if(e.result!=null){let[t]=e.result;t!=null&&(ee.extensionConfiguration=t)}}else if(e.result!=null&&e.result.title!=null&&e.result.title===Ka){let n=e.result.projectRootPath,r=await iy(n);if(r!=null){let i=Lm(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
+ ${D}`);let _={type:Vm.MessageType.Warning,message:`[Incremental typechecking] Something might have gone wrong with incremental type checking. Check out the [error log](file://${L}) and report this issue please.`};n({jsonrpc:G,method:"window/showMessage",params:_})}catch(L){console.error(L)}let K={jsonrpc:G,method:"textDocument/publishDiagnostics",params:{uri:(0,Wc.pathToFileURL)(e.file.sourceFilePath),diagnostics:H}};n(K)}r?.()});e.killCompilationListeners.push(()=>{u.kill("SIGKILL")})}catch(u){console.error(u)}}function Ym(e,t,n,r){Je()&&console.log("Updated: "+e),G_(e,t,n,r)}function Qm(e){Je()&&console.log("Closed: "+e);let t=hn.get(e);t!=null&&(Xm(e,t.project.rootPath),hn.delete(e),Vc.delete(t.file.originalTypeFileLocation))}function Zm(e){let t=hn.get(e);return t!=null?t.codeActions:null}var Km=new Set,Jc={},zc=null,Gc=!1,Xo=0,Xc=!1,Or=new Map,ry={},J=e=>{},iy=async e=>ee.extensionConfiguration.binaryPath!=null&&Ee.default.existsSync(oe.join(ee.extensionConfiguration.binaryPath,"rescript"))?oe.join(ee.extensionConfiguration.binaryPath,"rescript"):Im(e),Q_=new Mr.RequestType("textDocument/createInterface"),Z_=new Mr.RequestType("textDocument/openCompiled"),K_=e=>{let t=null;return Te.forEach((n,r)=>{t==null&&n.filesDiagnostics[e]!=null&&(t=n.filesDiagnostics[e].slice())}),t??[]},eP=async()=>{for(let[e,t]of Te){let{filesWithDiagnostics:n}=t,r=oe.join(e,Qa),i=Ee.default.readFileSync(r,{encoding:"utf-8"}),{done:o,result:s,codeActions:u,linesWithParseErrors:f}=await Vo(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,ry=u,Object.keys(s).forEach(m=>{let D={uri:m,diagnostics:s[m]};J({jsonrpc:G,method:"textDocument/publishDiagnostics",params:D}),n.add(m)}),o&&n.forEach(m=>{s[m]==null&&(J({jsonrpc:G,method:"textDocument/publishDiagnostics",params:{uri:m,diagnostics:[]}}),n.delete(m))})}},tP=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),ee.extensionConfiguration.incrementalTypechecking?.enable&&Bc(e))},nP=()=>{J({jsonrpc:G,method:"rescript/compilationFinished"})},Zn=!1,oy=async e=>{try{Zn&&console.log("syncing project config cache for "+e),await xt(e,["cache-project",e]),Zn&&console.log("OK - synced project config cache for "+e)}catch(t){Zn&&console.error(t)}},rP=async e=>{try{Zn&&console.log("deleting project config cache for "+e),await xt(e,["cache-delete",e]),Zn&&console.log("OK - deleted project config cache for "+e)}catch(t){Zn&&console.error(t)}};async function iP(e){await Promise.all(e.changes.map(async t=>{if(t.uri.includes("build.ninja")){if(ee.extensionConfiguration.cache?.projectConfig?.enable===!0){let n=Rt(t.uri);n!=null&&await oy(n)}}else if(t.uri.includes("compiler.log"))try{await eP(),nP(),ee.extensionConfiguration.inlayHints?.enable===!0&&sy(),ee.extensionConfiguration.codeLens===!0&&ay()}catch{console.log("Error while sending updated diagnostics")}else zm((0,fe.fileURLToPath)(t.uri))}))}var oP=async(e,t)=>{let n=(0,fe.fileURLToPath)(e);Or.set(n,t);let r=Rt(n);if(r!=null){let i=Te.get(r);if(i==null){ee.extensionConfiguration.incrementalTypechecking?.enable&&Gm(r);let u=Ir(r);i={openFiles:new Set,filesWithDiagnostics:new Set,filesDiagnostics:{},namespaceName:u.kind==="success"?u.result:null,rescriptVersion:await Lc(r),bsbWatcherByEditor:null,bscBinaryLocation:await Fc(r),editorAnalysisLocation:await Om(r),hasPromptedToStartBuild:/(\/|\\)node_modules(\/|\\)/.test(r)?"never":!1},Te.set(r,i),ee.extensionConfiguration.cache?.projectConfig?.enable===!0&&await oy(r)}Te.get(r).openFiles.add(n);let s=oe.join(r,Sp);if(i.hasPromptedToStartBuild===!1&&ee.extensionConfiguration.askToStartBuild===!0&&!Ee.default.existsSync(s))if(await iy(r)!=null){let u={title:Ka,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:Xo++,method:"window/showMessageRequest",params:f};J(m),i.hasPromptedToStartBuild=!0}else{let u={jsonrpc:G,method:"window/showMessage",params:{type:O.MessageType.Error,message:ee.extensionConfiguration.binaryPath==null?`Can't find ReScript binary in ${oe.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 ${ee.extensionConfiguration.binaryPath}`}};J(u)}}},sP=async e=>{let t=(0,fe.fileURLToPath)(e);ee.extensionConfiguration.incrementalTypechecking?.enable&&Qm(t),Or.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 rP(n),tP(n),r.bsbWatcherByEditor!==null&&(r.bsbWatcherByEditor.kill(),r.bsbWatcherByEditor=null)))}},aP=(e,t)=>{let n=(0,fe.fileURLToPath)(e);(0,Yc.assert)(Or.has(n)),Or.set(n,t),ee.extensionConfiguration.incrementalTypechecking?.enable&&Ym(n,t,J,()=>{ee.extensionConfiguration.codeLens&&ay(),ee.extensionConfiguration.inlayHints&&sy()})},mn=e=>{let t=(0,fe.fileURLToPath)(e),n=Or.get(t);return(0,Yc.assert)(n!=null),n};function Jo(e=!1){if(e){let t=new Go.StreamMessageWriter(gn.default.stdout),n=new Go.StreamMessageReader(gn.default.stdin);J=r=>t.write(r),n.listen(ny)}else J=t=>gn.default.send(t),gn.default.on("message",ny)}async function cP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=mn(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 uP(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,ee.extensionConfiguration.inlayHints?.maxLength],e)}function sy(){let e={jsonrpc:G,method:O.InlayHintRefreshRequest.method,id:Xo++};J(e)}async function lP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri);return await lt(n,["codeLens",n],e)}function ay(){let e={jsonrpc:G,method:O.CodeLensRefreshRequest.method,id:Xo++};J(e)}async function dP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=mn(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,ee.extensionConfiguration.signatureHelp?.forConstructorPayloads?"true":"false"],e);return Ee.default.unlink(i,()=>null),o}async function fP(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 pP(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 hP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=await $c(n,t.position);return{jsonrpc:G,id:e.id,result:r}}async function gP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=await $c(n,t.position),i=null;return r!==null&&r.forEach(o=>{if(oe.normalize((0,fe.fileURLToPath)(o.uri))===oe.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 mP(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 yP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=oe.extname(t.textDocument.uri),i=mn(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 ey(){let e={items:[{section:"rescript.settings"}]},t={jsonrpc:G,id:ec,method:O.ConfigurationRequest.type.method,params:e};J(t)}async function vP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=oe.extname(t.textDocument.uri),i=mn(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 bP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=mn(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 RP(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 DP(e){let t=e.params,n=(0,fe.fileURLToPath)(t.textDocument.uri),r=mn(t.textDocument.uri),i=oe.extname(t.textDocument.uri),o=Mt(i),s=[],u=ry[t.textDocument.uri]??[],f=Zm(n)??[];[...u,...f].forEach(({range:C,codeAction:$})=>{$m(C,t.range)&&s.push($)}),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:D}=m,P=D!=null&&Array.isArray(D)?[...s,...D]:s;return{jsonrpc:G,id:e.id,result:P.length>0?P:null}}function _P(e){let t={jsonrpc:G,id:e.id,result:[]},n=e.params,r=(0,fe.fileURLToPath)(n.textDocument.uri),i=oe.extname(n.textDocument.uri);if(i!==Ct&&i!==_r){let o={type:O.MessageType.Error,message:`Not a ${Ct} or ${_r} file. Cannot format it.`};return[t,{jsonrpc:G,method:"window/showMessage",params:o}]}else{let o=mn(n.textDocument.uri),s=Rt(r),f=(s!=null?Te.get(s):null)?.bscBinaryLocation??null,m=Mm(f,r,o);if(m.kind==="success"){let D=o.length,P=[{range:{start:{line:0,character:0},end:{line:D,character:D}},newText:m.result}];return[{jsonrpc:G,id:e.id,result:P}]}else return[t]}}var ty=async(e,t)=>{if(ee.extensionConfiguration.incrementalTypechecking?.enable)return;let n=(0,fe.fileURLToPath)(e),r=oe.extname(n),i=Mt(r);Ee.default.writeFileSync(i,t,{encoding:"utf-8"});let o=K_(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 PP(e){let t=e.params,n=oe.extname(t.uri),r=(0,fe.fileURLToPath)(t.uri),i=Rt(r);if(i===null){let $={type:O.MessageType.Error,message:"Cannot locate project directory to generate the interface file."};return{jsonrpc:G,method:"window/showMessage",params:$}}if(n!==Ct){let $={type:O.MessageType.Error,message:`Not a ${Ct} file. Cannot create an interface for it.`};return{jsonrpc:G,method:"window/showMessage",params:$}}let o=r.split(i)[1],s=Ir(i);if(s.kind==="error"){let $={type:O.MessageType.Error,message:"Error reading ReScript config file."};return{jsonrpc:G,method:"window/showMessage",params:$}}let u=s.result,f=u.length>0?"-"+u:"",m=oe.join(oe.dirname(o),oe.basename(o,Ct)+f+qp),D=oe.join(i,fn,m);if(!Ee.default.existsSync(D)){let $={type:O.MessageType.Error,message:"No compiled interface file found. Please compile your project first."};return{jsonrpc:G,method:"window/showMessage",params:$}}let T=await lt(r,["createInterface",r,D],e),C=typeof T.result=="string"?T.result:"";try{let $=Ro(r,_r);return Ee.default.writeFileSync($,C,{encoding:"utf-8"}),{jsonrpc:G,id:e.id,result:{uri:Ar($)}}}catch{return{jsonrpc:G,id:e.id,error:{code:O.ErrorCodes.InternalError,message:"Unable to create interface file."}}}}function wP(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=Fm(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:Ar(i.result)}}}async function ny(e){if(O.Message.isNotification(e)){if(!(!Gc&&e.method!=="exit"))if(e.method==="exit")Xc?gn.default.exit(0):gn.default.exit(1);else if(e.method===et.InitializedNotification.method){let t=Array.from(Km).flatMap(i=>[{globPattern:oe.join(i,"**",Qa),kind:O.WatchKind.Change|O.WatchKind.Create|O.WatchKind.Delete},{globPattern:oe.join(i,"**",vo),kind:O.WatchKind.Change|O.WatchKind.Create|O.WatchKind.Delete},{globPattern:`${oe.join(i,"**",fn)}/**/*.{cmt,cmi}`,kind:O.WatchKind.Change|O.WatchKind.Delete}]),n={registrations:[{id:"rescript_file_watcher",method:et.DidChangeWatchedFilesNotification.method,registerOptions:{watchers:t}}]},r={jsonrpc:G,id:Xo++,method:O.RegistrationRequest.method,params:n};J(r)}else if(e.method===et.DidChangeWatchedFilesNotification.method){let t=e.params;await iP(t)}else if(e.method===et.DidOpenTextDocumentNotification.method){let t=e.params;await oP(t.textDocument.uri,t.textDocument.text),await ty(t.textDocument.uri,t.textDocument.text)}else if(e.method===et.DidChangeTextDocumentNotification.method){let t=e.params,n=oe.extname(t.textDocument.uri);if(n===Ct||n===_r){let r=t.contentChanges;r.length===0||(aP(t.textDocument.uri,r[r.length-1].text),await ty(t.textDocument.uri,r[r.length-1].text))}}else if(e.method===et.DidCloseTextDocumentNotification.method){let t=e.params;await sP(t.textDocument.uri)}else e.method===et.DidChangeConfigurationNotification.type.method&&ey()}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);Km.add(u)}let n=t.initializationOptions?.extensionConfiguration;n!=null&&(ee.extensionConfiguration=n);let r=t.initializationOptions?.extensionClientCapabilities;r!=null&&(Jc=r),Jc.supportsSnippetSyntax=!!t.capabilities.textDocument?.completion?.completionItem?.snippetSupport;let i={capabilities:{textDocumentSync:Mr.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:ee.extensionConfiguration.inlayHints?.enable,codeLensProvider:ee.extensionConfiguration.codeLens?{workDoneProgress:!1}:void 0,signatureHelpProvider:ee.extensionConfiguration.signatureHelp?.enabled?{triggerCharacters:["("],retriggerCharacters:["=",","]}:void 0}},o={jsonrpc:G,id:e.id,result:i};Gc=!0,zc=setInterval(()=>{ey()},Np),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 cP(e));else if(e.method===O.DefinitionRequest.method)J(await fP(e));else if(e.method===O.TypeDefinitionRequest.method)J(await pP(e));else if(e.method===O.ReferencesRequest.method)J(await hP(e));else if(e.method===O.PrepareRenameRequest.method)J(await gP(e));else if(e.method===O.RenameRequest.method)J(await mP(e));else if(e.method===O.DocumentSymbolRequest.method)J(await yP(e));else if(e.method===O.CompletionRequest.method)J(await bP(e));else if(e.method===O.CompletionResolveRequest.method)J(await RP(e));else if(e.method===O.SemanticTokensRequest.method)J(await vP(e));else if(e.method===O.CodeActionRequest.method)J(await DP(e));else if(e.method===O.DocumentFormattingRequest.method)_P(e).forEach(n=>J(n));else if(e.method===Q_.method)J(await PP(e));else if(e.method===Z_.method)J(wP(e));else if(e.method===O.InlayHintRequest.method){let t=e.params;oe.extname(t.textDocument.uri)===Ct&&J(await uP(e))}else if(e.method===O.CodeLensRequest.method){let t=e.params;oe.extname(t.textDocument.uri)===Ct&&J(await lP(e))}else if(e.method===O.SignatureHelpRequest.method){let t=e.params;oe.extname(t.textDocument.uri)===Ct&&J(await dP(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===ec){if(e.result!=null){let[t]=e.result;t!=null&&(ee.extensionConfiguration=t)}}else if(e.result!=null&&e.result.title!=null&&e.result.title===Ka){let n=e.result.projectRootPath,r=await iy(n);if(r!=null){let i=Lm(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