/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ "use strict";var m=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var T=(r,s)=>{for(var t in s)m(r,t,{get:s[t],enumerable:!0})},V=(r,s,t,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let i of S(s))!P.call(r,i)&&i!==t&&m(r,i,{get:()=>s[i],enumerable:!(n=w(s,i))||n.enumerable});return r};var x=r=>V(m({},"__esModule",{value:!0}),r);var I={};T(I,{default:()=>h});module.exports=x(I);var b=require("child_process"),a=require("obsidian");var l=require("obsidian"),o={ribbonIcon:!0,ribbonCommandUsesCode:!0,showFileContextMenuItem:!0,executeTemplate:'code "{{vaultpath}}" "{{vaultpath}}/{{filepath}}"',urlProtocol:"vscode",openFile:!0,workspacePath:"{{vaultpath}}"},c=class extends l.PluginSettingTab{constructor(s,t){super(s,t),this.plugin=t}display(){let{containerEl:s}=this;s.empty(),s.createEl("h3",{text:"General settings"}),new l.Setting(s).setName("Display Ribbon Icon").setDesc("Toggle this OFF if you want to hide the Ribbon Icon.").addToggle(i=>i.setValue(this.plugin.settings.ribbonIcon).onChange(e=>{this.plugin.settings.ribbonIcon=e,this.plugin.saveSettings(),this.plugin.refreshIconRibbon()})),new l.Setting(s).setName("Ribbon opens via 'code' command").setDesc("Toggle this OFF if you'd prefer that the Ribbon Icon opens VS Code via URL.").addToggle(i=>i.setValue(this.plugin.settings.ribbonCommandUsesCode).onChange(e=>{this.plugin.settings.ribbonCommandUsesCode=e,this.plugin.saveSettings()})),new l.Setting(s).setName('Display "Open in VS Code" option for files/folders').setDesc('Toggle this OFF to hide the "Open in VS Code" option when right-clicking a file/folder.').addToggle(i=>i.setValue(this.plugin.settings.showFileContextMenuItem).onChange(e=>{this.plugin.settings.showFileContextMenuItem=e,this.plugin.saveSettings()})),s.createEl("h3",{text:"Open via 'code' CLI settings"});let t=document.createDocumentFragment();t.append(createEl("p",{text:"You can use the following variables: '{{vaultpath}}' (absolute), '{{filepath}}' (relative), '{{folderpath}}' (relative), '{{line}}' and '{{ch}}'."}),createEl("p",{text:`Example template: "'/usr/local/bin/code' '{{vaultpath}}' '{{vaultpath}}/{{filepath}}'"`}),createEl("span",{text:"For common issues, see the relevant part of the "}),createEl("a",{text:"readme",href:"https://github.com/NomarCub/obsidian-open-vscode#prerequisites"}),createEl("span",{text:"."})),new l.Setting(s).setName("Template for executing the 'code' command").setDesc(t).addText(i=>i.setPlaceholder(o.executeTemplate).setValue(this.plugin.settings.executeTemplate||o.executeTemplate).onChange(e=>{e=e.trim(),e===""&&(e=o.executeTemplate),this.plugin.settings.executeTemplate=e,this.plugin.saveData(this.plugin.settings)})),s.createEl("h3",{text:"Open via 'vscode://' URL settings"}),s.createEl("p",{text:"See: "}).appendChild(createEl("a",{text:"Opening VS Code with URLs",href:"https://code.visualstudio.com/docs/editor/command-line#_opening-vs-code-with-urls"})),new l.Setting(s).setName("Open current file").setDesc("Open the current file rather than the root of the vault.").addToggle(i=>i.setValue(this.plugin.settings.openFile||o.openFile).onChange(e=>{this.plugin.settings.openFile=e,this.plugin.saveData(this.plugin.settings)})),new l.Setting(s).setName("Path to VS Code Workspace").setDesc('Defaults to the {{vaultpath}} template variable. You can set this to an absolute path to a ".code-workspace" file if you prefer to use a ').addText(i=>i.setPlaceholder(o.workspacePath).setValue(this.plugin.settings.workspacePath||o.workspacePath).onChange(e=>{e=e.trim(),e===""&&(e=o.workspacePath),this.plugin.settings.workspacePath=e,this.plugin.saveData(this.plugin.settings)})).descEl.appendChild(createEl("a",{text:"multi-root workspace",href:"https://code.visualstudio.com/docs/editor/workspaces#_multiroot-workspaces"})).appendText("."),new l.Setting(s).setName("URL protocol").setDesc("You can override the default vscode:// to VS Code Insiders, VSCodium or other VS Code variants' protocol string").addText(i=>i.setPlaceholder(o.urlProtocol).setValue(this.plugin.settings.urlProtocol||o.urlProtocol).onChange(e=>{e=e.trim(),e===""&&(e=o.urlProtocol),this.plugin.settings.urlProtocol=e,this.plugin.saveData(this.plugin.settings)}))}};var p=class p extends a.Plugin{constructor(){super(...arguments);this.DEV=!1;this.logTag=`[${this.manifest.id}]`}async onload(){this.DEV&&console.log(`Loading ${this.manifest.name} plugin`),(0,a.addIcon)(p.iconId,p.iconSvgContent),await this.loadSettings(),this.refreshIconRibbon(),this.addSettingTab(new c(this.app,this)),this.addCommand({id:"open-vscode",name:"Open as Visual Studio Code workspace",callback:this.openVSCode.bind(this)}),this.addCommand({id:"open-vscode-via-url",name:"Open as Visual Studio Code workspace using a vscode:// URL",callback:this.openVSCodeUrl.bind(this)}),this.registerEvent(this.app.workspace.on("file-menu",this.fileMenuHandler.bind(this)));let t=this.app.plugins.getPlugin("hot-reload");this.DEV=t?.enabledPlugins.has(this.manifest.id)??!1,this.DEV&&(this.addCommand({id:"open-vscode-reload",name:"Reload the plugin in dev",callback:this.reload.bind(this)}),this.addCommand({id:"open-vscode-reset-settings",name:"Reset plugins settings to default in dev",callback:this.resetSettings.bind(this)}))}openVSCode(t=this.app.workspace.getActiveFile()){if(!(this.app.vault.adapter instanceof a.FileSystemAdapter))return;let n=this.app.vault.adapter.getBasePath(),i=t?.path??"",e=t?.parent?.path??"",d=this.app.workspace.getActiveViewOfType(a.MarkdownView)?.editor.getCursor(),v=(d?.line??0)+1,C=(d?.ch??0)+1,g=this.settings.executeTemplate.trim()||o.executeTemplate,u=g.replaceAll("{{vaultpath}}",n).replaceAll("{{filepath}}",i).replaceAll("{{folderpath}}",e).replaceAll("{{line}}",v.toString()).replaceAll("{{ch}}",C.toString());this.DEV&&console.log(this.logTag,{executeTemplate:g,command:u}),(0,b.exec)(u,f=>{f&&(new a.Notice("Failed to launch VS Code. Check the plugin's settings and your logs for more details."),console.error(`${this.logTag} exec error. template: ${g} command: ${u} `,f))})}openVSCodeUrl(){if(!(this.app.vault.adapter instanceof a.FileSystemAdapter))return;let t=this.app.vault.adapter.getBasePath(),i=this.app.workspace.getActiveFile()?.path??"";this.DEV&&console.log(this.logTag,{settings:this.settings,path:t,filePath:i});let e=`${this.settings.urlProtocol}://file/${t}`;if(this.settings.openFile){e+=`/${i}`;let d=this.settings.workspacePath.replaceAll("{{vaultpath}}",t);window.open(`${this.settings.urlProtocol}://file/${d}`),setTimeout(()=>{this.DEV&&console.log(this.logTag,{url:e}),window.open(e)},200)}else this.DEV&&console.log(this.logTag,{url:e}),window.open(e)}async loadSettings(){this.settings=Object.assign({},o,await this.loadData())}async saveSettings(t=this.settings){await this.saveData(t)}refreshIconRibbon(){this.ribbonIcon?.remove(),this.settings.ribbonIcon&&(this.ribbonIcon=this.addRibbonIcon(p.iconId,"VS Code",()=>{this.settings.ribbonCommandUsesCode?this.openVSCode():this.openVSCodeUrl()}))}fileMenuHandler(t,n){this.settings.showFileContextMenuItem&&t.addItem(i=>{i.setTitle("Open in VS Code").setIcon(p.iconId).onClick(()=>{this.openVSCode(n)})})}async reload(){let t=this.manifest.id,n=this.app.plugins;await n.disablePlugin(t),await n.enablePlugin(t),console.log(`${this.logTag} reloaded`,this)}async resetSettings(){console.log(this.logTag,{old:this.settings,default:o}),this.settings=o,await this.saveData(this.settings)}};p.iconId="vscode-logo",p.iconSvgContent=` Visual Studio Code `;var h=p; /* nosourcemap */