UNPKG

vscode-solidity-server

Version:

Ethereum Solidity Language for Visual Studio Code

43 lines (42 loc) 151 kB
#!/usr/bin/env node "use strict"; function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var Wi=Object.defineProperty;var an=Object.getOwnPropertySymbols;var $i=Object.prototype.hasOwnProperty,Bi=Object.prototype.propertyIsEnumerable;var cn=(r,i,e)=>i in r?Wi(r,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[i]=e,ee=(r,i)=>{for(var e in i||(i={}))$i.call(i,e)&&cn(r,e,i[e]);if(an)for(var e of an(i))Bi.call(i,e)&&cn(r,e,i[e]);return r};var z=(r=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(r,{get:(i,e)=>(typeof require!="undefined"?require:i)[e]}):r)(function(r){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var St=(r,i,e)=>new Promise((t,n)=>{var s=l=>{try{a(e.next(l))}catch(u){n(u)}},o=l=>{try{a(e.throw(l))}catch(u){n(u)}},a=l=>l.done?t(l.value):Promise.resolve(l.value).then(s,o);a((e=e.apply(r,i)).next())});var _path = require('path'); var ki = _interopRequireWildcard(_path); var De = _interopRequireWildcard(_path); var te = _interopRequireWildcard(_path); var w = _interopRequireWildcard(_path); var k = _interopRequireWildcard(_path); var Be = _interopRequireWildcard(_path); var y = _interopRequireWildcard(_path); var ae = _interopRequireWildcard(_path); var xn = _interopRequireWildcard(_path); var Wt = _interopRequireWildcard(_path);var _vscodelanguageserver = require('vscode-languageserver'); var kn = _interopRequireWildcard(_vscodelanguageserver);function un(r){switch(r){case"error":return _vscodelanguageserver.DiagnosticSeverity.Error;case"warning":return _vscodelanguageserver.DiagnosticSeverity.Warning;case"info":return _vscodelanguageserver.DiagnosticSeverity.Information;default:return _vscodelanguageserver.DiagnosticSeverity.Error}}function vt(r){if(r.formattedMessage!==void 0&&r.sourceLocation===void 0)return{diagnostic:{message:r.formattedMessage,code:r.errorCode,range:{end:{character:0,line:0},start:{character:0,line:0}},severity:un(r.severity)},fileName:""};if(r.sourceLocation.file!==void 0&&r.sourceLocation.file!==null){let i=r.sourceLocation.file,e=r.formattedMessage.substr(r.formattedMessage.indexOf(i)).split(":"),t=1;return process.platform==="win32"&&(t=2),ln(r,e,t,i)}else{let i=r.formattedMessage.split(":"),e=i[0],t=1;return process.platform==="win32"&&(e=i[0]+":"+i[1],t=2),ln(r,i,t,e)}}function ln(r,i,e,t){let n=un(r.severity),s=r.message,o=parseInt(i[e]);Number.isNaN(o)&&(o=1);let a=parseInt(i[e+1]);Number.isNaN(a)&&(a=1);let l=a-1,u=a+r.sourceLocation.end-r.sourceLocation.start-1;u<0&&(u=1);let p=o-1,b=o-1;return r.code==="1878"&&(b=0,p=2,u=0,l=1),{diagnostic:{message:s,code:r.errorCode,range:{end:{character:u,line:p},start:{character:l,line:b}},severity:n},fileName:t}}var _solc = require('solc'); var xe = _interopRequireWildcard(_solc);var _fs = require('fs'); var U = _interopRequireWildcard(_fs); var Re = _interopRequireWildcard(_fs); var pn = _interopRequireWildcard(_fs); var F = _interopRequireWildcard(_fs); var Rt = _interopRequireWildcard(_fs); var Ye = _interopRequireWildcard(_fs); var Dn = _interopRequireWildcard(_fs); var Qt = _interopRequireWildcard(_fs);var _https = require('https'); var Mt = _interopRequireWildcard(_https);function $e(r){return r!==null?r.replace(/\\/g,"/"):r}function It(r,i){return r.forEach(function(e,t){let n=e.split("=")[0];for(let s of i){let o=s.split("=")[0];if(n===o){r[t]=s;break}}}),[...new Set([...r,...i])]}function mn(r,i,e){let t=w.dirname(w.resolve(i));for(;t!==e;){if(Hi(r,t))return t;t=w.dirname(t)}return null}function Hi(r,i){for(let e of r){let t=w.join(i,e);if(pn.existsSync(t))return!0}return!1}function dn(r,i){let e=w.relative(r,i);return e&&!e.startsWith("..")&&!w.isAbsolute(e)}var Ie=class r{static getAllLibraryImports(i){let e=/^\s?import\s+[^'"]*['"](.*)['"]\s*/gm,t=[],n=e.exec(i);for(;n!=null;){let s=n[1];this.isImportLocal(s)||t.push(s),n=e.exec(i)}return t}static isImportLocal(i){return i.startsWith(".")}constructor(i,e,t){this.absolutePath=this.formatDocumentPath(i),this.code=e,this.unformattedCode=e,this.project=t,this.imports=new Array}resolveImportPath(i){if(this.isImportLocal(i))return this.formatDocumentPath(te.resolve(te.dirname(this.absolutePath),i));if(this.project!==void 0&&this.project!==null){let e=this.project.findImportRemapping(i);if(e!==void 0&&e!=null)return this.formatDocumentPath(e.resolveImport(i));{let t=this.project.findDependencyPackage(i);if(t!==void 0)return this.formatDocumentPath(t.resolveImport(i))}}return te.resolve(this.project.projectPackage.absoluletPath,i)}getAllImportFromPackages(){let i=new Array;return this.imports.forEach(e=>{this.isImportLocal(e)||i.push(e)}),i}isImportLocal(i){return r.isImportLocal(i)}formatDocumentPath(i){return $e(i)}replaceDependencyPath(i,e){let t=/(^\s?import\s+[^'"]*['"])(.*)(['"]\s*)/gm;this.code=this.code.replace(t,(n,s,o,a)=>o===i?s+e+a:n)}resolveImports(){let i=/^\s?import\s+[^'"]*['"](.*)['"]\s*/gm,e=i.exec(this.code);for(;e!=null;){let t=e[1];if(this.isImportLocal(t)){let n=this.formatDocumentPath(te.resolve(te.dirname(this.absolutePath),e[1]));this.imports.push(n)}else this.imports.push(t);e=i.exec(this.code)}}};var G=class{static getAllLibraryImports(i){let e=[];return i.forEach(t=>e=e.concat(Ie.getAllLibraryImports(t))),[...new Set(e)]}constructor(){this.documents=new Array}isDocumentPathTheSame(i,e){return i.absolutePath===e}containsSourceDocument(i){return this.documents.findIndex(e=>e.absolutePath===i)>-1}getDefaultSourceDocumentsForCompilation(i=200,e="",t=!1){let n={"*":{"":["ast"],"*":["abi","devdoc","userdoc","storageLayout","metadata","evm.bytecode","evm.deployedBytecode","evm.methodIdentifiers","evm.gasEstimates"]}};return this.getSourceDocumentsForCompilation(!0,i,e,t,n)}getDefaultSourceDocumentsForCompilationDiagnostics(i="",e=!1){let t={"*":{"":[],"*":[]}};return this.getSourceDocumentsForCompilation(!1,0,i,e,t)}getSourceDocumentsForCompilation(i,e,t="",n=!1,s){let o={};return this.documents.forEach(a=>{o[a.absolutePath]={content:a.code}}),t===""||t===void 0||t===null?{language:"Solidity",settings:{optimizer:{enabled:i,runs:e},outputSelection:s,viaIR:!0},sources:o}:{language:"Solidity",settings:{optimizer:{enabled:i,runs:e},outputSelection:s,evmVersion:t},sources:o}}addSourceDocumentAndResolveImports(i,e,t){let n=this.addSourceDocument(i,e,t);return n!==null&&(n.resolveImports(),n.imports.forEach(s=>{if(Re.existsSync(s)){if(!this.containsSourceDocument(s)){let o=this.readContractCode(s);o!=null&&this.addSourceDocumentAndResolveImports(s,o,t)}}else this.addSourceDocumentAndResolveDependencyImport(s,n,t)})),n}addSourceDocument(i,e,t){if(!this.containsSourceDocument(i)){let n=new Ie(i,e,t);return this.documents.push(n),n}return null}formatContractPath(i){return $e(i)}getAllImportFromPackages(){let i=new Array;return this.documents.forEach(e=>{e.getAllImportFromPackages().forEach(n=>{i.indexOf(n)<0&&i.push(n)})}),i}readContractCode(i){return Re.existsSync(i)?Re.readFileSync(i,"utf8"):null}addSourceDocumentAndResolveDependencyImport(i,e,t){let n=t.findImportRemapping(i);if(n!=null){let s=this.formatContractPath(n.resolveImport(i));this.addSourceDocumentAndResolveDependencyImportFromContractFullPath(s,t,e,i)}else{let s=t.findDependencyPackage(i);if(s!==void 0){let o=this.formatContractPath(s.resolveImport(i));this.addSourceDocumentAndResolveDependencyImportFromContractFullPath(o,t,e,i)}}}addSourceDocumentAndResolveDependencyImportFromContractFullPath(i,e,t,n){if(this.containsSourceDocument(i))t.replaceDependencyPath(n,i);else{let s=this.readContractCode(i);s!=null&&(this.addSourceDocumentAndResolveImports(i,s,e),t.replaceDependencyPath(n,i))}}};var _os = require('os'); var hn = _interopRequireWildcard(_os);var _toml = require('@iarna/toml'); var gn = _interopRequireWildcard(_toml);var _yamljs = require('yaml-js'); var bn = _interopRequireWildcard(_yamljs);var Te=class{constructor(i){this.sol_sources_alternative_directories=[];this.build_dir="bin",i!==null&&i.length>0?(this.sol_sources=i[0],this.sol_sources_alternative_directories=i):this.sol_sources=""}appendToSolSourcesAternativeDirectories(i){this.sol_sources_alternative_directories=[...new Set(this.sol_sources_alternative_directories.concat(i))]}getSolSourcesAbsolutePath(){return this.sol_sources!==void 0||this.sol_sources===""?Be.join(this.absoluletPath,this.sol_sources):this.absoluletPath}isImportForThis(i){let e=i.split("/");return e.length===1?!1:e[0]===this.name}resolveImport(i){if(this.isImportForThis(i)){let e=Be.join(this.getSolSourcesAbsolutePath(),i.substring(this.name.length));if(Rt.existsSync(e))return e;for(let t=0;t<this.sol_sources_alternative_directories.length;t++){let n=this.sol_sources_alternative_directories[t];if(n!==void 0||n===""){let s=Be.join(this.absoluletPath,n,i.substring(this.name.length));if(Rt.existsSync(s))return s}}}return null}};var Tt=class{isImportForThis(i){return this.context!==void 0?i.startsWith(this.context+":"+this.prefix):i.startsWith(this.prefix)}getLibraryPathIfRelative(i){if(!y.isAbsolute(this.target)){let e=y.join(this.basePath,this.target);if(dn(i,e))return y.dirname(this.target).split(y.sep)[0]}return null}createImportFromFile(i){if(this.isFileForThis(i))if(y.isAbsolute(this.target)){if(this.context===void 0)return y.join(this.prefix,i.substring(this.target.length));if(this.context!==void 0)return y.join(this.context+":"+this.prefix,i.substring(this.target.length))}else{if(this.context===void 0)return y.join(this.prefix,i.substring(y.join(this.basePath,this.target).length));if(this.context!==void 0)return y.join(this.context+":"+this.prefix,i.substring(y.join(this.basePath,this.target).length))}}isFileForThis(i){return y.isAbsolute(this.target)?i.startsWith(this.target):i.startsWith(y.join(this.basePath,this.target))}resolveImport(i){if(i==null)return null;let e=this.isImportForThis(i);if(y.isAbsolute(this.target)){if(e&&this.context===void 0)return y.join(this.target,i.substring(this.prefix.length));if(e&&this.context!==void 0)return y.join(this.target,i.substring((this.context+":"+this.prefix).length))}else{if(e&&this.context===void 0)return y.join(this.basePath,this.target,i.substring(this.prefix.length));if(e&&this.context!==void 0)return y.join(this.basePath,this.target,i.substring((this.context+":"+this.prefix).length))}return null}};function fn(r,i){let e=new Array;return r!==void 0&&r.length>0&&r.forEach(t=>{let n=new Tt;n.basePath=i.projectPackage.absoluletPath;let o=new RegExp("((?<context>[\\S]+)\\:)?(?<prefix>[\\S]+)=(?<target>.+)","g").exec(t);o&&(o.groups.context&&(n.context=o.groups.context),o.groups.prefix&&(n.prefix=o.groups.prefix,n.target=o.groups.target,e.push(n)))}),e}var _glob = require('glob'); var Ln = _interopRequireWildcard(_glob);var He=class{constructor(i,e,t,n){this.projectPackage=i,this.dependencies=e,this.packagesDir=t,this.remappings=fn(n,this)}findDependencyPackage(i){return this.dependencies.find(e=>e.isImportForThis(i))}getAllSolFilesIgnoringDependencyFolders(){let i=this.projectPackage.getSolSourcesAbsolutePath()+"/**/*.sol",e=[];return this.packagesDir.forEach(t=>{e.push(ae.join(this.projectPackage.getSolSourcesAbsolutePath(),t,"**"))}),e.push(ae.join(this.projectPackage.getSolSourcesAbsolutePath(),this.projectPackage.build_dir,"**")),this.getAllRelativeLibrariesAsExclusionsFromRemappings().forEach(t=>e.push(t)),_glob.glob.sync(i,{ignore:e,nodir:!0})}getAllRelativeLibrariesAsExclusionsFromRemappings(){return this.getAllRelativeLibrariesRootDirsFromRemappingsAbsolutePaths().map(i=>ae.join(i,"**"))}getAllRelativeLibrariesRootDirsFromRemappings(){let i=[];return this.remappings.forEach(e=>{let t=e.getLibraryPathIfRelative(this.projectPackage.getSolSourcesAbsolutePath());t!==null&&i.find(n=>n===t)===void 0&&i.push(t)}),i}getAllRelativeLibrariesRootDirsFromRemappingsAbsolutePaths(){return this.getAllRelativeLibrariesRootDirsFromRemappings().map(i=>ae.resolve(this.projectPackage.getSolSourcesAbsolutePath(),i))}findImportRemapping(i){let e=[];return this.remappings.forEach(t=>{t.isImportForThis(i)&&e.push(t)}),e.length>0?this.sortByLength(e)[e.length-1]:null}findRemappingForFile(i){let e=[];return this.remappings.forEach(t=>{t.isFileForThis(i)&&e.push(t)}),e.length>0?this.sortByLength(e)[e.length-1]:null}sortByLength(i){return i.sort(function(e,t){return e.length-t.length})}};var yn="dappFile",Cn="remappings.txt",Pn="brownie-config.yaml",Yi="hardhat.config.js",Ji="hardhat.config.ts",Xi="truffle-config.js",Sn="foundry.toml",Qi=[Cn,Pn,Sn,Yi,Ji,Xi,yn];var Zi=["","src","contracts"],Ki=["","src","contracts"];function vn(r,i){return mn(Qi,i,r)}function xt(r,i){let e=k.join(r,yn);if(F.existsSync(e)){let t=In(e),n=new Te(i);return n.absoluletPath=r,t&&(t.layout!==void 0&&(n.build_dir!==void 0&&(n.build_dir=t.layout.build_dir),n.sol_sources!==void 0&&(n.sol_sources=t.layout.sol_sources)),n.name!==void 0?n.name=t.name:n.name=k.basename(r),n.version!==void 0&&(n.version=t.name),n.dependencies!==void 0&&(n.dependencies=t.dependencies)),n}return null}function In(r){let i=F.readFileSync(r);return bn.load(i)}function ze(r,i,e,t){Zi=e;let n=or(r,e),s=[...new Set(Ki.concat(e))],o=er(i,r,n,s);return t=rr(r,t),new He(n,o,i,t)}function er(r,i,e,t){let n=[];return r.forEach(s=>{n=n.concat(Dt(i,e,s,t))}),n}function tr(r){let i=k.join(r,Sn);if(F.existsSync(i)){try{let e=F.readFileSync(i,"utf8"),t=gn.parse(e),n;return n=t.profile.default.remappings,!n||n.length===0?null:n}catch(e){console.log(e.message),console.log(e.stack)}return}return null}function nr(r){let i=k.join(r,Pn);if(F.existsSync(i)){let e=In(i),t;try{if(t=e.compiler.solc.remappings,!t)return}catch(s){return}return t.map(s=>{let[o,a]=s.split("=");return a.startsWith("/")?`${o}=${a}`:`${o}=${k.join(hn.homedir(),".brownie","packages",a)}`})}return null}function ir(r){let i=k.join(r,Cn);if(F.existsSync(i)){let e=[],n=F.readFileSync(i,"utf8").split(/\r\n|\r|\n/);return n&&n.forEach(s=>{e.push(s)}),e}return null}function rr(r,i){var e,t,n;return i===void 0&&(i=[]),i=(n=(t=(e=nr(r))!=null?e:ir(r))!=null?t:tr(r))!=null?n:i,i}function Dt(r,i,e,t,n=new Array){i.dependencies!==void 0&&Object.keys(i.dependencies).forEach(o=>{if(!n.some(a=>a.name===o)){let a=k.join(r,e,o),l=xt(a,[""]);l.appendToSolSourcesAternativeDirectories(t),l!==null&&(n.push(l),Dt(r,l,e,t,n))}});let s=k.join(i.absoluletPath,e);return F.existsSync(s)&&sr(s).forEach(a=>{let l=k.join(s,a),u=xt(l,null);u==null&&(u=Rn(l),u.appendToSolSourcesAternativeDirectories(t)),n.some(p=>p.name===u.name)||(n.push(u),Dt(r,u,e,t,n))}),n}function sr(r){return F.readdirSync(r).filter(function(i){let e=k.join(r,i);return F.statSync(e).isDirectory()})}function Rn(r,i=[""]){let e=new Te(i);return e.absoluletPath=r,e.name=k.basename(r),e}function or(r,i=[""]){let e=xt(r,i);return e===null&&(e=Rn(r,i)),e}var le=(n=>(n[n.localNodeModule=0]="localNodeModule",n[n.remote=1]="remote",n[n.localFile=2]="localFile",n[n.embedded=3]="embedded",n))(le||{}),ce=class{getVersion(){return this.localSolc.version()}isInitialisedAlready(i=null){return this.localSolc===null?!1:this.matchesConfiguration(i)}},Et=class extends ce{matchesConfiguration(i){return!0}getConfiguration(){return""}constructor(){super(),this.compilerType=3}init(){this.localSolc=null}canCompilerBeLoaded(){return!0}initialiseCompiler(){return new Promise((i,e)=>{this.localSolc=z("solc"),i()})}},At=class extends ce{constructor(){super();this.npmModule="solc",this.compilerType=0}matchesConfiguration(e){return e===this.npmModule}getConfiguration(){return this.npmModule}init(e,t="solc"){e!==this.rootPath&&(this.localSolc=null,this.rootPath=e),this.matchesConfiguration(t)||(this.npmModule=t,this.localSolc=null)}canCompilerBeLoaded(){return this.isInstalledSolcUsingNode(this.rootPath)}getLocalSolcNodeInstallation(){return De.join(this.rootPath,"node_modules",this.npmModule,"soljson.js")}isInstalledSolcUsingNode(e){return U.existsSync(this.getLocalSolcNodeInstallation())}initialiseCompiler(){return new Promise((e,t)=>{if(this.isInitialisedAlready(this.npmModule)&&e(),this.canCompilerBeLoaded())try{let n=z(this.getLocalSolcNodeInstallation());this.localSolc=xe.setupMethods(n),e()}catch(n){this.localSolc=null,t("An error has ocurred, loading the compiler from Node Modules, located at:"+this.getLocalSolcNodeInstallation()+", "+n)}else this.localSolc=null,t("Compiler cannot be loaded from: "+this.getLocalSolcNodeInstallation())})}},Ft=class extends ce{constructor(){super();this.compilerType=2}matchesConfiguration(e){return e===this.localPath}getConfiguration(){return this.localPath}init(e){this.matchesConfiguration(e)||(this.localPath=e,this.localSolc=null)}canCompilerBeLoaded(){return typeof this.localPath!="undefined"&&this.localPath!==null&&this.localPath!==""?this.compilerExistsAtPath(this.localPath):!1}compilerExistsAtPath(e){return U.existsSync(e)}initialiseCompiler(){return new Promise((e,t)=>{if(this.isInitialisedAlready(this.localPath)&&e(),this.canCompilerBeLoaded())try{let n=z(this.localPath);this.localSolc=xe.setupMethods(n),e()}catch(n){this.localSolc=null,t("An error has ocurred, loading the compiler located at:"+this.localPath+", "+n)}else this.localSolc=null,t("Compiler cannot be loaded from: "+this.localPath)})}},Lt=class{downloadCompilationFile(i,e){let t=U.createWriteStream(e),n="https://binaries.soliditylang.org/bin/soljson-"+i+".js";return new Promise((s,o)=>{Mt.get(n,function(l){l.statusCode!==200?o("Error retrieving solidity compiler: "+l.statusMessage):(l.pipe(t),t.on("finish",function(){t.close(),s()}))}).on("error",function(l){o(l)}).end()})}},kt=class{getSolcReleases(){let i="https://binaries.soliditylang.org/bin/list.json";return new Promise((e,t)=>{Mt.get(i,n=>{let s="";n.on("data",o=>{s+=o}),n.on("end",()=>{try{let o=JSON.parse(s);e(o.releases)}catch(o){t(o.message)}})}).on("error",n=>{t(n.message)})})}getFullVersionFromFileName(i){let e="",t=i;if(t!=="undefined")e=t.replace("soljson-",""),e=e.replace(".js","");else throw"Remote version: Invalid file name";return e}resolveRelease(i){return St(this,null,function*(){return new Promise((e,t)=>St(this,null,function*(){i==="latest"&&e(i);try{let n=yield this.getSolcReleases();for(let s in n){let o=this.getFullVersionFromFileName(n[s]);i===o&&e(o),i===s&&e(o),i===n[s]&&e(o),"v"+s===i&&e(o),i.startsWith("v"+s+"+commit")&&e(o)}t("Remote version: invalid version")}catch(n){t(n)}}))})}},jt=class extends ce{constructor(){super();this.compilerType=1}getConfiguration(){return this.configuredVersion}matchesConfiguration(e){return typeof this.configuredVersion!="undefined"&&this.configuredVersion!==null&&this.configuredVersion!==""?this.localSolc!==null?this.getVersion().startsWith(e.substring(1))&&this.configuredVersion===e:this.configuredVersion===e:!1}setSolcCache(e){this.solcCachePath=e}initVersion(e){console.log("initVersion"),console.log(e),this.matchesConfiguration(e)||(this.configuredVersion=e,this.localSolc=null)}canCompilerBeLoaded(){return typeof this.configuredVersion!="undefined"&&this.configuredVersion!==null&&this.configuredVersion!==""}initialiseCompiler(){return new Promise((e,t)=>{if(this.isInitialisedAlready(this.configuredVersion)&&e(),this.canCompilerBeLoaded()){let n=this;new kt().resolveRelease(this.configuredVersion).then(s=>this.loadRemoteVersionRetry(s,1,3).then(o=>{n.localSolc=o,e()}).catch(o=>{t("There was an error loading the remote version: "+this.configuredVersion+","+o)})).catch(s=>{t("There was an error loading the remote version: "+this.configuredVersion+","+s)})}else this.localSolc=null,t("Compiler cannot load remote version:"+this.configuredVersion)})}loadRemoteVersionRetry(e,t,n){return new Promise((s,o)=>{this.loadRemoteVersion(e).then(a=>s(a)).catch(a=>{if(t<=n)return this.loadRemoteVersionRetry(e,t+1,n);o(a)})})}loadRemoteVersion(e){let t=De.resolve(De.join(this.solcCachePath,"soljson-"+e+".js"));return new Promise((n,s)=>{try{if(U.existsSync(t)&&e!=="latest"){let o=z(t),a=xe.setupMethods(o);n(a)}else new Lt().downloadCompilationFile(e,t).then(()=>{let o=z(t),a=xe.setupMethods(o);n(a)}).catch(o=>s(o))}catch(o){if(U.existsSync(t))return U.unlinkSync(t),this.loadRemoteVersion(e);s(o)}})}},qe=class{constructor(i){this.rootPath=i,this.nodeCompiler=new At,this.localCompiler=new Ft,this.remoteCompiler=new jt,this.embeddedCompiler=new Et,this.selectedCompiler=3}setSolcCache(i){this.remoteCompiler.setSolcCache(i)}isRootPathSet(){return typeof this.rootPath!="undefined"&&this.rootPath!==null}initialisedAlready(i,e){if(e===1)return this.remoteCompiler.isInitialisedAlready(i);if(e===2)return this.localCompiler.isInitialisedAlready(i);if(e===0)return this.nodeCompiler.isInitialisedAlready(i);if(e===3)return this.embeddedCompiler.isInitialisedAlready()}initialiseAllCompilerSettings(i,e,t,n){this.nodeCompiler.init(this.rootPath,t),this.remoteCompiler.initVersion(i),this.localCompiler.init(e),this.embeddedCompiler.init(),this.selectedCompiler=n}initialiseSelectedCompiler(){return this.getCompiler().initialiseCompiler()}initialiseCompiler(i){return this.getCompiler(i).initialiseCompiler()}compile(i,e=null){return this.getCompiler(e).localSolc.compile(i)}getLoadedVersion(){var e;return(e=this.getCompiler().localSolc)==null?void 0:e.version()}getLoadedCompilerType(){let i=this.getCompiler();return le[i.compilerType]}getSelectedVersion(){return this.getCompiler().getConfiguration()}getCompiler(i=null){switch(i==null&&(i=this.selectedCompiler),i){case 3:return this.embeddedCompiler;case 0:return this.nodeCompiler;case 2:return this.localCompiler;case 1:return this.remoteCompiler;default:throw new Error("Invalid compiler")}}compileSolidityDocumentAndGetDiagnosticErrors(i,e,t,n,s,o=null,a="",l=!1){if(o==null&&(o=this.selectedCompiler),this.isRootPathSet()){let u=new G;u.addSourceDocumentAndResolveImports(i,e,ze(this.rootPath,t,n,s));let p=u.getDefaultSourceDocumentsForCompilationDiagnostics(a,l);p.settings.optimizer=null,p.settings.outputSelection=null;let b=this.compile(JSON.stringify(p),o),S=JSON.parse(b);if(S.errors)return S.errors.map(d=>vt(d))}else{let u={};u[i]=e;let p=this.compile({sources:u});if(p.errors)return p.errors.map(b=>vt(b))}return[]}};var _solhint = require('solhint'); var ar = _interopRequireWildcard(_solhint);var Ee=class{constructor(i,e,t){this.config=new wt(i,e),this.linter=t?z(xn.join(i,t)):ar}loadFileConfig(i){this.config.loadFileConfig(i)}setIdeRules(i){this.config.setIdeRules(i)}validate(i,e){return this.linter.processStr(e,this.config.build(),i).messages.map(t=>this.toDiagnostic(t))}toDiagnostic(i){return{message:`Linter: ${i.message} [${i.ruleId}]`,range:this.rangeOf(i),severity:this.severity(i)}}severity(i){return i.severity===3?_vscodelanguageserver.DiagnosticSeverity.Warning:_vscodelanguageserver.DiagnosticSeverity.Error}rangeOf(i){let e=i.line-1,t=i.column-1;return{start:{line:e,character:t},end:{line:e,character:t+1}}}},ne=class ne{constructor(i,e){this.setIdeRules(e),this.loadFileConfig(i)}setIdeRules(i){this.ideRules=i||{}}build(){let i=["solhint:recommended"];this.fileConfig.extends!=="undefined"&&this.fileConfig.extends!==null&&(i=this.fileConfig.extends);let e=[];return this.fileConfig.plugins!=="undefined"&&this.fileConfig.plugins!==null&&(console.log(`pluginsConfig: ${this.fileConfig.plugins}`),e=this.fileConfig.plugins),{extends:i,plugins:e,rules:Object.assign(ne.DEFAULT_RULES,this.ideRules,this.fileConfig.rules)}}isRootPathSet(i){return typeof i!="undefined"&&i!==null}loadFileConfig(i){if(this.isRootPathSet(i)){let e=`${i}/.solhint.json`;this.readFileConfig.bind(this,e)(),this.currentWatchFile=e}else this.fileConfig=ne.EMPTY_CONFIG}readFileConfig(i){this.fileConfig=ne.EMPTY_CONFIG,Ye.existsSync(i)&&(this.fileConfig=JSON.parse(Ye.readFileSync(i,"utf-8")))}};ne.DEFAULT_RULES={"func-visibility":!1},ne.EMPTY_CONFIG={rules:{}};var wt=ne;var _solium = require('solium'); var Je = _interopRequireWildcard(_solium);var cr={},ue=class ue{constructor(i,e,t){this.vsConnection=t,this.loadFileConfig(i),this.setIdeRules(e)}isRootPathSet(i){return typeof i!="undefined"&&i!==null}setIdeRules(i){typeof i=="undefined"||i===null?this.soliumRules=cr:this.soliumRules=i,(typeof this.soliumRules.indentation=="undefined"||this.soliumRules.indentation===null)&&(this.soliumRules.indentation="false"),process.platform==="win32"&&(typeof this.soliumRules["linebreak-style"]=="undefined"||this.soliumRules["linebreak-style"]===null)&&(this.soliumRules["linebreak-style"]="off")}lintAndFix(i){return Je.lintAndFix(i,this.getAllSettings())}getAllSettings(){return this.fileConfig!==ue.EMPTY_CONFIG&&this.fileConfig!==!1?this.fileConfig:{extends:"solium:recommended",options:{returnInternalIssues:!0},plugins:["security"],rules:this.soliumRules}}validate(i,e){let t=[];try{t=Je.lint(e,this.getAllSettings())}catch(n){let s=/An error .*?\nSyntaxError: (.*?) Line: (\d+), Column: (\d+)/.exec(n.message);if(s){let o=parseInt(s[2],10)-1,a=parseInt(s[3],10)-1;return[{message:`Syntax error: ${s[1]}`,range:{end:{character:a,line:o},start:{character:a,line:o}},severity:_vscodelanguageserver.DiagnosticSeverity.Error}]}else this.vsConnection.console.error("solium error: "+n)}return t.map(this.soliumLintResultToDiagnostic)}soliumLintResultToDiagnostic(i){let e=i.type==="warning"?_vscodelanguageserver.DiagnosticSeverity.Warning:_vscodelanguageserver.DiagnosticSeverity.Error,t=i.line-1;return{message:`Linter: ${i.ruleName}: ${i.message}`,range:{end:{character:i.node.end,line:t},start:{character:i.column,line:t}},severity:e}}loadFileConfig(i){if(this.isRootPathSet(i)){let e=`${i}/.soliumrc.json`;this.readFileConfig.bind(this,e)(),this.currentWatchFile=e}else this.fileConfig=ue.EMPTY_CONFIG}readFileConfig(i){this.fileConfig=ue.EMPTY_CONFIG,Dn.readFile(i,"utf-8",this.onConfigLoaded.bind(this))}onConfigLoaded(i,e){this.fileConfig=!i&&JSON.parse(e)}};ue.EMPTY_CONFIG={rules:{}};var Ae=ue;var _url = require('url');var _vscodelanguageservertextdocument = require('vscode-languageserver-textdocument');var _vscodeuri = require('vscode-uri');var f=class r{static create(i,e=null,t=null){let n=new r;return n.location=e,n.isCurrentElementSelected=i,n.reference=t,n}static filterFoundResults(i){let e=i.filter(t=>t.isCurrentElementSelected===!0);if(e.length>0){let t=e.filter(n=>n.location!==null);return t.length>0?t:[r.create(!0)]}else return[]}},h=class{constructor(){this.name="";this.contract=null;this.supportsNatSpec=!0;this.comment=null}initialise(i,e,t=null,n=!1){this.contract=t,this.element=i,this.name=i.name,this.document=e,this.isGlobal=n,t!==null&&n===!1&&(this.isGlobal=!0)}getHover(){return{contents:this.getMarkupInfo()}}getMarkupInfo(){return{kind:_vscodelanguageserver.MarkupKind.Markdown,value:this.getInfo()}}getInfo(){return"### "+this.name+` `+this.getComment()}getSelectedItem(i){return this.isCurrentElementedSelected(i)?this:null}generateNatSpec(){return null}isCommentLine(i,e){if(e===0)return!1;let t=i.getText(this.getLineRange(e)).trimStart();return!(!t.startsWith("///")&&!t.startsWith("*")&&!t.startsWith("/**")&&!t.startsWith("/*!")&&!t.startsWith("*/"))}getSimpleInfo(){return this.name||"Unnamed"}extractContractName(i){let e=/@inheritdoc\s+(\w+)/,t=i.match(e);return t&&t.length>1?t[1]:null}getLineRange(i){return _vscodelanguageserver.Range.create(_vscodelanguageserver.Position.create(i,0),_vscodelanguageserver.Position.create(i+1,0))}getContractNameOrGlobal(){return this.contract!=null?this.contract.getContractTypeName(this.contract.contractType)+": "+this.contract.name:"Global"}getComment(){if(this.comment===null&&this.supportsNatSpec){let i=_vscodeuri.URI.file(this.document.sourceDocument.absolutePath).toString(),e=_vscodelanguageservertextdocument.TextDocument.create(i,null,null,this.document.sourceDocument.unformattedCode),t=e.positionAt(this.element.start),n="",s=t.line-1;for(;this.isCommentLine(e,s);){let o=e.getText(this.getLineRange(s)).trimStart();s=s-1;let a=this.extractContractName(o);a&&this.contract!==null?n=" "+o+this.contract.getInheritedComment(this.name,a)+n:n=" "+o+n}this.comment=n}return this.comment}createFoundReferenceLocationResult(){return f.create(!0,this.getLocation(),this)}createNotFoundReferenceLocationResult(){return f.create(!1)}createFoundReferenceLocationResultNoLocation(){return f.create(!0,null,this)}isTheSame(i){try{let e=i===this,t=this.document.sourceDocument.absolutePath===i.document.sourceDocument.absolutePath&&this.name===i.name&&this.element.start===i.element.start&&this.element.end===i.element.end;return e||t}catch(e){}}getAllReferencesToObject(i){return this.isTheSame(i)?[this.createFoundReferenceLocationResult()]:[]}findElementByOffset(i,e){return i.find(t=>t.start<=e&&e<=t.end)}isElementedSelected(i,e){return i!=null&&i.start<=e&&e<=i.end}createCompletionItem(){return null}isCurrentElementedSelected(i){return this.isElementedSelected(this.element,i)}getLocation(){let i=_vscodeuri.URI.file(this.document.sourceDocument.absolutePath).toString(),e=_vscodelanguageservertextdocument.TextDocument.create(i,null,null,this.document.sourceDocument.unformattedCode);return _vscodelanguageserver.Location.create(e.uri,_vscodelanguageserver.Range.create(e.positionAt(this.element.start),e.positionAt(this.element.end)))}getRange(){let i=_vscodeuri.URI.file(this.document.sourceDocument.absolutePath).toString(),e=_vscodelanguageservertextdocument.TextDocument.create(i,null,null,this.document.sourceDocument.unformattedCode);return _vscodelanguageserver.Range.create(e.positionAt(this.element.start),e.positionAt(this.element.end))}getSelectedTypeReferenceLocation(i){return this.isCurrentElementedSelected(i)?[f.create(!0)]:[f.create(!1)]}getAllReferencesToSelected(i,e){return this.isCurrentElementedSelected(i)?this.getAllReferencesToThis(e):[]}getAllReferencesToThis(i){let e=[];e.push(this.createFoundReferenceLocationResult());let t=[];return i.forEach(n=>{t.push(...n.getDocumentsThatReference(this.document))}),t=[...new Set(t)],t.forEach(n=>{e.push(...n.getAllReferencesToObject(this))}),e}findTypeInScope(i){return i=this.findMappingValueType(i),this.contract===null?this.document.findType(i):this.contract.findType(i)}findMappingValueType(i){if(typeof i.type!="undefined"&&i.type==="MappingExpression"){let e=i.to;if(typeof e=="string")return e;if(typeof e.type!="undefined"&&e.type==="MappingExpression")return this.findMappingValueType(e);if(e&&typeof e.literal!="undefined")return e.literal;if(e&&typeof e.name!="undefined")return e.name}return i}findMethodsInScope(i){return this.contract===null?this.document.findMethodCalls(i):this.contract.findMethodCalls(i)}findMembersInScope(i){return this.contract===null?this.document.findMembersInScope(i):this.contract.findMembersInScope(i)}getInnerCompletionItems(){return[]}getInnerMembers(){return[]}getInnerMethodCalls(){return[]}getParsedObjectType(){return""}mergeArrays(i,e){for(let t=0;t<e.length;t++)i.indexOf(e[t])===-1&&i.push(e[t]);return i}};var v=class r extends h{constructor(){super(...arguments);this.parentTypeName=null;this.type=null;this.mappingValueType=null;this.mappingKeyType=null}static create(e,t,n){let s=new r;return s.initialise(e,n,t),s}initialise(e,t,n,s=!1){super.initialise(e,t,n,s),e.members!==void 0&&e.members.length>0?(this.name=e.members[0],this.parentTypeName=e.literal):e.literal.literal!==void 0?this.name=e.literal.literal:this.name=e.literal,this.isArray=e.array_parts.length>0,this.isMapping=!1;let o=e.literal;typeof o.type!="undefined"&&(this.isMapping=o.type==="MappingExpression",this.isMapping&&(this.name="mapping",this.mappingKeyType=this.getTypeString(o.from),this.mappingValueType=this.getTypeString(o.to)))}getInnerCompletionItems(){let e=[];if(this.getExtendedMethodCallsFromUsing().forEach(n=>e.push(n.createCompletionItem())),this.isMapping&&this.mappingValueType!==null){let n=this.findTypeInScope(this.mappingValueType);if(n!=null)return e.concat(n.getInnerCompletionItems())}let t=this.findType();return t==null?e:e.concat(t.getInnerCompletionItems())}getInnerMembers(){if(this.isMapping&&this.mappingValueType!==null){let t=this.findTypeInScope(this.mappingValueType);if(t!=null)return t.getInnerMembers()}let e=this.findType();return e==null?[]:e.getInnerMembers()}getInnerMethodCalls(){let e=[];if(e=e.concat(this.getExtendedMethodCallsFromUsing()),this.isMapping&&this.mappingValueType!==null){let n=this.findTypeInScope(this.mappingValueType);if(n!=null)return e.concat(n.getInnerMethodCalls())}let t=this.findType();return t==null?e:e.concat(t.getInnerMethodCalls())}getExtendedMethodCallsFromUsing(){let e=[];this.contract!==null?e=this.contract.getAllUsing(this):e=this.document.getAllGlobalUsing(this);let t=[];return e.forEach(n=>{let s=this.document.getAllContracts().find(o=>o.name===n.name);if(s!==void 0){let a=s.getAllFunctions().filter(l=>{if(l.input.length>0){let u=l.input[0].type,p=!1;return(u.name===this.name||this.name==="address_payable"&&u.name==="address")&&(p=!0),u.isArray===this.isArray&&p&&u.isMapping===this.isMapping}return!1});t=t.concat(a)}}),t}findType(){if(this.type===null)if(this.parentTypeName!==null){let e=this.findTypeInScope(this.parentTypeName);e!==void 0&&(this.type=e.findTypeInScope(this.name))}else this.type=this.findTypeInScope(this.name);if(this.isMapping&&this.mappingValueType!==null){let e=this.findTypeInScope(this.mappingValueType);if(e!=null)return e}return this.type}getAllReferencesToSelected(e,t){return this.isCurrentElementedSelected(e)?this.findType().getAllReferencesToThis(t):[]}getAllReferencesToObject(e){if(this.isTheSame(e))return[this.createFoundReferenceLocationResult()];let t=this.findType();return this.type!=null&&this.type.isTheSame(e)?[this.createFoundReferenceLocationResult()]:[]}getInfo(){let e="";this.isArray&&(e=`### Array `),this.isMapping&&(e="### Mapping ("+this.mappingKeyType+" => "+this.getMappingValueInfo(this.mappingValueType)+`) `);let t=this.findType();return this.type!=null?e+t.getInfo():e+"### "+this.name}getMappingValueInfo(e){if(typeof e.type!="undefined"&&e.type==="MappingExpression"){let t=this.getTypeString(e.from),n=e.to;if(typeof n=="string")return"Mapping ("+t+" => "+n+")";if(typeof n.type!="undefined"&&n.type==="MappingExpression")return"Mapping ("+t+" => "+this.findMappingValueType(n)+")";if(n&&typeof n.literal!="undefined")return"Mapping ("+t+" => "+n.literal+")";if(n&&typeof n.name!="undefined")return"Mapping ("+t+" => "+n.name+")"}return e}getSimpleInfo(){let e="";this.isArray&&(e="Array:"),this.isMapping&&(e="Mapping:");let t=this.findType();return this.type!=null?e+t.getSimpleInfo():e+" "+this.name}getTypeString(e){return typeof e=="string"?e:e&&typeof e.literal!="undefined"?e.literal:e&&typeof e.name!="undefined"?e.name:"unknown"}};var M=class extends h{getSelectedTypeReferenceLocation(e){if(this.isCurrentElementedSelected(e)){let t=this.type.findType();return t!==void 0?[t.createFoundReferenceLocationResult()]:[this.createFoundReferenceLocationResultNoLocation()]}return[this.createNotFoundReferenceLocationResult()]}toDocumentSymbol(){let e=this.name||"Unnamed",t=this.getRange();return _vscodelanguageserver.DocumentSymbol.create(e,this.type.getSimpleInfo(),_vscodelanguageserver.SymbolKind.Variable,t,t)}getAllReferencesToObject(e){return this.isTheSame(e)?[this.createFoundReferenceLocationResult()]:this.type.getAllReferencesToObject(e)}};var Xe=class extends M{constructor(){super(...arguments);this.completionItem=null}initialise(e,t,n){super.initialise(e,t,n),this.name=e.name,this.type=v.create(e.literal,n,t)}createCompletionItem(){if(this.completionItem===null){let e=_vscodelanguageserver.CompletionItem.create(this.name);e.kind=_vscodelanguageserver.CompletionItemKind.Field,e.documentation=this.getMarkupInfo(),this.completionItem=e}return this.completionItem}toDocumentSymbolType(){let e=this.name||"Unnamed",t=this.getRange();return _vscodelanguageserver.DocumentSymbol.create(e,this.type.getSimpleInfo(),_vscodelanguageserver.SymbolKind.Variable,t,t)}getParsedObjectType(){return"State Variable"}getInfo(){return"### "+this.getParsedObjectType()+": "+this.name+` #### `+this.getContractNameOrGlobal()+` `+this.getComment()+` ### Type Info: `+this.type.getInfo()+` `}};var q=class extends h{constructor(){super(...arguments);this.items=[];this.completionItem=null}initialise(e,t,n,s){super.initialise(e,t,n,s),this.name=e.name,this.id=e.id,e.members.forEach(o=>{this.items.push(o)})}toDocumentSymbol(){let e=this.getRange();return _vscodelanguageserver.DocumentSymbol.create(this.name,this.getSimpleInfo(),_vscodelanguageserver.SymbolKind.Enum,e,e)}getSimpleInfo(){let e=this.items.map(t=>t).join(", ");return`Enum ${this.name} { ${e} }`}createCompletionItem(){if(this.completionItem===null){let e=_vscodelanguageserver.CompletionItem.create(this.name);e.kind=_vscodelanguageserver.CompletionItemKind.Enum;let t="";this.isGlobal?t=this.document.getGlobalPathInfo():t=this.contract.name,e.insertText=this.name,e.documentation=this.getMarkupInfo(),this.completionItem=e}return this.completionItem}getInnerCompletionItems(){let e=[];return this.items.forEach(t=>e.push(_vscodelanguageserver.CompletionItem.create(t))),e}getParsedObjectType(){return"Enum"}getInfo(){return"### "+this.getParsedObjectType()+": "+this.name+` #### `+this.getContractNameOrGlobal()+` `+this.getComment()}};var Qe=class extends M{constructor(){super(...arguments);this.completionItem=null}initialiseStructVariable(e,t,n,s){this.element=e,this.name=e.name,this.document=n,this.type=v.create(e.literal,t,n),this.struct=s}createCompletionItem(){if(this.completionItem===null){let e=_vscodelanguageserver.CompletionItem.create(this.name);e.documentation=this.getMarkupInfo(),this.completionItem=e}return this.completionItem}toDocumentSymbolType(){let e=this.name||"Unnamed",t=this.getRange();return _vscodelanguageserver.DocumentSymbol.create(e,this.type.getSimpleInfo(),_vscodelanguageserver.SymbolKind.Variable,t,t)}getParsedObjectType(){return"Struct Property"}getInfo(){return"### "+this.getParsedObjectType()+": "+this.name+` #### `+this.struct.getParsedObjectType()+": "+this.struct.name+` #### `+this.getContractNameOrGlobal()+` ### Type Info: `+this.type.getInfo()+` `}};var Y=class extends h{constructor(){super(...arguments);this.properties=[];this.completionItem=null}initialise(e,t,n,s){this.contract=n,this.element=e,this.id=e.id,this.name=e.name,this.document=t,this.isGlobal=s,this.element.body!=="undefined"&&this.element.body.forEach(o=>{if(o.type==="DeclarativeExpression"){let a=new Qe;a.initialiseStructVariable(o,this.contract,this.document,this),this.properties.push(a)}})}toDocumentSymbol(){let e=this.name||"Unnamed",t=this.getRange(),n=_vscodelanguageserver.DocumentSymbol.create(e,this.getSimpleInfo(),_vscodelanguageserver.SymbolKind.Struct,t,t);return n.children=this.properties.map(s=>s.toDocumentSymbolType()),n}getSimpleInfo(){let e=this.properties.map(t=>`${t.name}: ${t.type.getSimpleInfo()}`).join(", ");return`Struct ${this.name} { ${e} }`}getInnerMembers(){return this.properties}getVariableSelected(e){return this.properties.find(t=>t.isCurrentElementedSelected(e))}getSelectedItem(e){if(this.isCurrentElementedSelected(e)){let t=this.getVariableSelected(e);return t!==void 0?t:this}return null}getSelectedTypeReferenceLocation(e){if(this.isCurrentElementedSelected(e)){let t=this.getVariableSelected(e);return t!==void 0?t.getSelectedTypeReferenceLocation(e):[f.create(!0)]}return[f.create(!1)]}createCompletionItem(){if(this.completionItem===null){let e=_vscodelanguageserver.CompletionItem.create(this.name);e.kind=_vscodelanguageserver.CompletionItemKind.Struct,e.insertText=this.name,e.documentation=this.getMarkupInfo(),this.completionItem=e}return this.completionItem}getInnerCompletionItems(){let e=[];return this.properties.forEach(t=>e.push(t.createCompletionItem())),e}getAllReferencesToSelected(e,t){if(this.isCurrentElementedSelected(e)){let n=this.getSelectedProperty(e);return n!==void 0?n.getAllReferencesToThis(t):this.getAllReferencesToThis(t)}return[]}getSelectedProperty(e){return this.properties.find(t=>t.isCurrentElementedSelected(e))}getParsedObjectType(){return"Struct"}getInfo(){return"### "+this.getParsedObjectType()+": "+this.name+` #### `+this.getContractNameOrGlobal()+` `+this.getComment()}};var ie=class{static getTypeString(i){let e=i.array_parts.length>0,t=!1,n,s=null;i.members!==void 0&&i.members.length>0?(n=i.members[0],s=i.literal):n=i.literal;let o="";return typeof n.type!="undefined"&&(t=n.type==="MappingExpression",t&&(o="("+this.getTypeString(n.from)+" => "+this.getTypeString(n.to)+")")),e&&(o=o+"[]"),t?"mapping"+o:s!==null?s+"."+n+o:n+o}};var C=class r extends M{constructor(){super(...arguments);this.completionItem=null}static extractParameters(e,t,n,s){let o=[];return typeof e!="undefined"&&e!==null&&(e.hasOwnProperty("params")&&(e=e.params),e.forEach(a=>{let l=new r;l.initialiseParameter(a,t,n,s),o.push(l)})),o}static createParamsInfo(e){let t="";return typeof e!="undefined"&&e!==null&&(e.hasOwnProperty("params")&&(e=e.params),e.forEach(n=>{let s=r.getParamInfo(n);t===""?t=s:t=t+`, `+s})),t}static getParamInfo(e){let t=ie.getTypeString(e.literal),n="";return typeof e.id!="undefined"&&e.id!==null?n=t+" "+e.id:n=t,n}static createFunctionParamsSnippet(e,t=!1){let n="",s=0;return typeof e!="undefined"&&e!==null&&e.forEach(o=>{if(t&&s===0)t=!1;else{let a=ie.getTypeString(o.literal);s=s+1;let l="${"+s+":"+o.id+"}";n===""?n=l:n=n+", "+l}}),n}getAllReferencesToSelected(e,t){return this.isCurrentElementedSelected(e)?this.type.isCurrentElementedSelected(e)?this.type.getAllReferencesToSelected(e,t):this.getAllReferencesToThis(t):[]}getAllReferencesToObject(e){return this.isTheSame(e)?[this.createFoundReferenceLocationResult()]:this.type.getAllReferencesToObject(e)}getAllReferencesToThis(e){let t=[];return t.push(this.createFoundReferenceLocationResult()),t.concat(this.parent.getAllReferencesToObject(this))}initialiseParameter(e,t,n,s){this.element=e,this.name=e.name,this.document=n,this.contract=t,this.parent=s;let o=v.create(e.literal,t,n);this.element=e,this.type=o,typeof e.id!="undefined"&&e.id!==null&&(this.name=e.id)}createParamCompletionItem(e,t){if(this.completionItem===null){let n="[parameter name not set]";this.element.id!==null&&(n=this.element.id);let s=_vscodelanguageserver.CompletionItem.create(n);s.kind=_vscodelanguageserver.CompletionItemKind.Variable,s.documentation=this.getMarkupInfo(),this.completionItem=s}return this.completionItem}getParsedObjectType(){return"Parameter"}getInfo(){let e="Name not set";return this.name!==void 0&&(e=this.name),"### "+this.getParsedObjectType()+": "+e+` #### `+this.parent.getParsedObjectType()+": "+this.parent.name+` #### `+this.getContractNameOrGlobal()+` ### Type Info: `+this.type.getInfo()+` `}getSignature(){return r.getParamInfo(this.element)}toDocumentSymbolType(e){let t=this.name||"Unnamed",n=this.getRange();return _vscodelanguageserver.DocumentSymbol.create(t,`${e}: ${this.type.getSimpleInfo()}`,_vscodelanguageserver.SymbolKind.Variable,n,n)}};var pe=class extends h{constructor(){super(...arguments);this.input=[];this.completionItem=null}initialise(e,t,n,s=!1){super.initialise(e,t,n,s),this.name=e.name,this.id=e.id,this.initialiseParamters()}initialiseParamters(){this.input=C.extractParameters(this.element.params,this.contract,this.document,this)}toDocumentSymbol(){let e=this.getRange(),t=_vscodelanguageserver.DocumentSymbol.create(this.name,this.getSimpleInfo(),_vscodelanguageserver.SymbolKind.Event,e,e);return t.children=this.input.map(n=>n.toDocumentSymbolType("Input Parameter")),t}getSimpleInfo(){let e=this.input.map(t=>`${t.name}: ${t.type.getSimpleInfo()}`).join(", ");return`Event ${this.name}(${e})`}createCompletionItem(e=!1){if(this.completionItem===null){let t=_vscodelanguageserver.CompletionItem.create(this.name);t.kind=_vscodelanguageserver.CompletionItemKind.Event;let n=C.createFunctionParamsSnippet(this.element.params,e);t.insertTextFormat=2,t.insertText=this.name+"("+n+");",t.documentation=this.getMarkupInfo(),this.completionItem=t}return this.completionItem}getSelectedTypeReferenceLocation(e){if(this.isCurrentElementedSelected(e)){let t=[];this.input.forEach(s=>t=this.mergeArrays(t,s.getSelectedTypeReferenceLocation(e)));let n=f.filterFoundResults(t);return n.length>0?n:[f.create(!0)]}return[f.create(!1)]}getSelectedItem(e){let t=null;if(this.isCurrentElementedSelected(e)){let n=[];return n=n.concat(this.input),t=n.find(s=>s.getSelectedItem(e)),t!=null?t:this}return t}getParsedObjectType(){return"Event"}getInfo(){return"### "+this.getParsedObjectType()+": "+this.name+` #### `+this.getContractNameOrGlobal()+` `+this.getSignature()+` `+this.getComment()}getDeclaration(){return"event"}getSignature(){let e=C.createParamsInfo(this.element.params);return this.getDeclaration()+" "+this.name+"("+e+`) `}};var Fe=class extends M{constructor(){super(...arguments);this.completionItem=null}createCompletionItem(){if(this.completionItem===null){let e=_vscodelanguageserver.CompletionItem.create(this.name);e.kind=_vscodelanguageserver.CompletionItemKind.Field;let t="";this.function.isGlobal?t=this.document.getGlobalPathInfo():t=this.function.contract.name;let n=ie.getTypeString(this.element.literal);e.detail="(Function variable in "+this.function.name+") "+n+" "+t,this.completionItem=e}return this.completionItem}getAllReferencesToThis(){let e=[];return e.push(this.createFoundReferenceLocationResult()),e.concat(this.function.getAllReferencesToObject(this))}getAllReferencesToSelected(e,t){return this.isCurrentElementedSelected(e)?this.type.isCurrentElementedSelected(e)?this.type.getAllReferencesToSelected(e,t):this.getAllReferencesToThis():[]}getParsedObjectType(){return"Function Variable"}getInfo(){return"### "+this.getParsedObjectType()+": "+this.name+` #### `+this.function.getParsedObjectType()+": "+this.function.name+` #### `+this.getContractNameOrGlobal()+` ### Type Info: `+this.type.getInfo()+` `}getSignature(){return C.getParamInfo(this.element)}toDocumentSymbolType(){let e=this.name||"Unnamed",t=this.getRange();return _vscodelanguageserver.DocumentSymbol.create(e,`Variable: ${this.type.getSimpleInfo()}`,_vscodelanguageserver.SymbolKind.Variable,t,t)}};var Ze=class extends h{initialiseModifier(e,t,n){this.functionParent=t,this.contract=t.contract,this.element=e,this.name=e.name,this.document=n}isPublic(){return this.name==="public"}isPrivate(){return this.name==="private"}isExternal(){return this.name==="external"}isInternal(){return this.name==="internal"}isView(){return this.name==="pure"}isPure(){return this.name==="view"}isPayeable(){return this.name==="payeable"}IsCustomModifier(){return!(this.isPublic()||this.isExternal()||this.isPrivate()||this.isView()||this.isPure()||this.isPayeable()||this.isInternal())}getSelectedTypeReferenceLocation(e){if(this.isCurrentElementedSelected(e)){let t=[];if(this.IsCustomModifier()){let n=this.findMethodsInScope(this.name);return n.length>0&&n.forEach(s=>{t.push(f.create(!0,s.getLocation()))}),t}return[f.create(!0)]}return[f.create(!1)]}getAllReferencesToObject(e){if(this.IsCustomModifier()&&e instanceof D){let t=e;if(t.isModifier&&t.name===this.name)return[this.createFoundReferenceLocationResult()]}return[]}getAllReferencesToSelected(e,t){if(this.isCurrentElementedSelected(e)){let n=[];if(this.IsCustomModifier())return this.findMethodsInScope(this.name).forEach(o=>n=n.concat(o.getAllReferencesToThis(t))),n}return[]}getParsedObjectType(){return"Modifier Argument"}getInfo(){if(this.IsCustomModifier()){let e=this.findMethodsInScope(this.name);return e.length>0?"### "+this.getParsedObjectType()+": "+this.name+` #### `+this.functionParent.getParsedObjectType()+": "+this.functionParent.name+` #### `+this.getContractNameOrGlobal()+` ### Type Info: `+e[0].getInfo()+` `:"### "+this.getParsedObjectType()+": "+this.name+` #### `+this.functionParent.getParsedObjectType()+": "+this.functionParent.name+` #### `+this.getContractNameOrGlobal()+` `}}};var D=class extends h{constructor(){super(...arguments);this.input=[];this.output=[];this.modifiers=[];this.variables=[];this.expressions=[];this.isConstructor=!1;this.isFallback=!1;this.isReceive=!1;this.completionItem=null}getAllReferencesToSelected(e,t){let n=[];return this.isCurrentElementedSelected(e)&&(this.input.forEach(s=>n=n.concat(s.getAllReferencesToSelected(e,t))),this.output.forEach(s=>n=n.concat(s.getAllReferencesToSelected(e,t))),this.expressions.forEach(s=>n=n.concat(s.getAllReferencesToSelected(e,t))),this.variables.forEach(s=>n=n.concat(s.getAllReferencesToSelected(e,t))),this.modifiers.forEach(s=>n=n.concat(s.getAllReferencesToSelected(e,t))),n.length===0&&this.isElementedSelected(this.id,e))?this.getAllReferencesToThis(t):n}getSelectedItem(e){let t=null;if(this.isCurrentElementedSelected(e)){let n=[];n=n.concat(this.input).concat(this.output).concat(this.expressions).concat(this.variables).concat(this.modifiers);for(let s of n)if(s!==null&&(t=s.getSelectedItem(e),t!==null))return t;return this}return t}toDocumentSymbol(){let e=this.getRange(),t=_vscodelanguageserver.DocumentSymbol.create(this.name||this.getParsedObjectType(),this.getSimpleInfo(),this.getSymbolKind(),e,e);return t.children=[...this.input.map(n=>n.toDocumentSymbolType("Input Parameter")),...this.output.map(n=>n.toDocumentSymbolType("Output Parameter")),...this.variables.map(n=>n.toDocumentSymbolType())],t}getSimpleInfo(){let e=this.input.map(o=>`${o.name}: ${o.type.getSimpleInfo()}`).join(", "),t=this.output.map(o=>o.type.getSimpleInfo()).join(", "),n=this.modifiers.map(o=>o.name).join(" ");return`${this.isModifier?"Modifier":this.isConstructor?"Constructor":this.isFallback?"Fallback":this.isReceive?"Receive":"Function"} ${this.name}(${e})${t?" returns ("+t+")":""}${n?" "+n:""}`}getSymbolKind(){return this.isConstructor?_vscodelanguageserver.SymbolKind.Constructor:this.isReceive?_vscodelanguageserver.SymbolKind.Method:this.isFallback?_vscodelanguageserver.SymbolKind.Method:this.isModifier