From ef1b927861f9a949aed20341144ffb5bfd42f038 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 19 Sep 2022 11:22:21 +1000 Subject: Removing the web client --- javascript/app/utils/go-to-definition.js | 89 -------------------------------- 1 file changed, 89 deletions(-) delete mode 100644 javascript/app/utils/go-to-definition.js (limited to 'javascript/app/utils/go-to-definition.js') diff --git a/javascript/app/utils/go-to-definition.js b/javascript/app/utils/go-to-definition.js deleted file mode 100644 index 59b5dba..0000000 --- a/javascript/app/utils/go-to-definition.js +++ /dev/null @@ -1,89 +0,0 @@ -function exactLocationToUrl(exactLocation) { - const modulePath = exactLocation.modulePath; - const packageId = exactLocation.packageId.name + "-" + exactLocation.packageId.version; - let hash = ""; - if(exactLocation.startLine != 1) { - hash = "#L" + exactLocation.startLine; - } - return "/package/"+packageId+"/show/"+modulePath+hash; -} - -function hackageUrl(packageId,locationInfo) { - let hash = ""; - if (locationInfo.entity !== "Mod") { - hash = "#" + encodeURIComponent(locationInfo.name); - } - return "https://hackage.haskell.org/package/"+packageId+"/docs/src/"+locationInfo.moduleName+".html"+hash; -} - -function openUrl(buttonId,url) { - if(buttonId === 2) {//middle mouse button - window.open(url, '_blank'); - } else if(buttonId == 1) {//left mouse button - window.location = url; - } - return false; -} - -function saveCurrentLocation(currentLineNumber) { - if(currentLineNumber) { - const url = window.location.origin + window.location.pathname + "#L" + currentLineNumber; - if(location.href != url) { - window.location.hash = "#L" + currentLineNumber; - } - } -} - -function goToDefinition(store,locationInfo,buttonId,currentLineNumber) { - if(locationInfo.tag === "ExactLocation") { - const url = exactLocationToUrl(locationInfo); - if(locationInfo.startLine !== currentLineNumber) { - saveCurrentLocation(currentLineNumber); - } - openUrl(buttonId,url); - } else if((locationInfo.tag === "ApproximateLocation") && - (locationInfo.moduleName.indexOf("Paths_") !== 0)) { - const packageId = locationInfo.packageId.name+"-"+locationInfo.packageId.version; - if(locationInfo.entity === "Mod") { - store.loadDefinitionSite(packageId, - locationInfo.moduleName, - locationInfo.componentId, - locationInfo.entity, - locationInfo.moduleName) - .then((defSite) => { - const packageId = defSite.location.packageId.name + "-" + defSite.location.packageId.version; - openUrl(buttonId,"/package/" + packageId + "/show/" + defSite.location.modulePath); - }).catch(() => { - openUrl(buttonId,hackageUrl(packageId,locationInfo)); - }); - } else { - store.loadDefinitionSite(packageId, - locationInfo.moduleName, - locationInfo.componentId, - locationInfo.entity, - locationInfo.name) - .then((definitionSite) => { - if(definitionSite.location.tag === "ExactLocation") { - const url = exactLocationToUrl(definitionSite.location); - if(locationInfo.startLine !== currentLineNumber) { - saveCurrentLocation(currentLineNumber); - } - openUrl(buttonId,url); - } else { - saveCurrentLocation(currentLineNumber); - openUrl(buttonId,hackageUrl(packageId,locationInfo)); - } - }).catch((e) => { - console.log(e); - saveCurrentLocation(currentLineNumber); - openUrl(buttonId,hackageUrl(packageId,locationInfo)); - }); - } - } else { - alert('No location info'); - } -} - -export { - goToDefinition,openUrl -} -- cgit v1.2.3