code-server
Version:
Run VS Code on a remote server.
3 lines (2 loc) • 5.81 kB
JavaScript
;var B=Object.create;var m=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var R=(t,a)=>{for(var s in a)m(t,s,{get:a[s],enumerable:!0})},E=(t,a,s,o)=>{if(a&&typeof a=="object"||typeof a=="function")for(let n of W(a))!j.call(t,n)&&n!==s&&m(t,n,{get:()=>a[n],enumerable:!(o=L(a,n))||o.enumerable});return t};var N=(t,a,s)=>(s=t!=null?B(F(t)):{},E(a||!t||!t.__esModule?m(s,"default",{value:t,enumerable:!0}):s,t)),V=t=>E(m({},"__esModule",{value:!0}),t);var st={};R(st,{activate:()=>U,deactivate:()=>q});module.exports=V(st);var w=require("fs"),I=require("net"),_=require("path"),e=N(require("vscode"));var X={disabled:e.l10n.t("Auto Attach: Disabled"),always:e.l10n.t("Auto Attach: Always"),smart:e.l10n.t("Auto Attach: Smart"),onlyWithFlag:e.l10n.t("Auto Attach: With Flag")},M={disabled:e.l10n.t("Disabled"),always:e.l10n.t("Always"),smart:e.l10n.t("Smart"),onlyWithFlag:e.l10n.t("Only With Flag")},$={disabled:e.l10n.t("Auto attach is disabled and not shown in status bar"),always:e.l10n.t("Auto attach to every Node.js process launched in the terminal"),smart:e.l10n.t("Auto attach when running scripts that aren't in a node_modules folder"),onlyWithFlag:e.l10n.t("Only auto attach when the `--inspect` flag is given")},J=e.l10n.t("Toggle Auto Attach"),C=e.l10n.t("Toggle auto attach in this workspace"),D=e.l10n.t("Toggle auto attach on this machine"),H=e.l10n.t("Temporarily disable auto attach in this session"),K=e.l10n.t("Re-enable auto attach"),Q=e.l10n.t("Auto Attach: Disabled"),k="extension.node-debug.toggleAutoAttach",S="jsDebugIpcState",f="debug.javascript",g="autoAttachFilter",x=new Set(["autoAttachSmartPattern",g].map(t=>`${f}.${t}`)),T,d,p,u=!1;function U(t){T=Promise.resolve({context:t,state:null}),t.subscriptions.push(e.commands.registerCommand(k,G.bind(null,t))),t.subscriptions.push(e.workspace.onDidChangeConfiguration(a=>{(a.affectsConfiguration(`${f}.${g}`)||[...x].some(s=>a.affectsConfiguration(s)))&&O()})),A(b())}async function q(){await y()}function O(){A("disabled"),A(b())}function z(t){if(t){if(t.workspaceFolderValue)return e.ConfigurationTarget.WorkspaceFolder;if(t.workspaceValue)return e.ConfigurationTarget.Workspace;if(t.globalValue)return e.ConfigurationTarget.Global}else return e.ConfigurationTarget.Global;return e.ConfigurationTarget.Global}async function G(t,a){let s=e.workspace.getConfiguration(f);a=a||z(s.inspect(g));let o=a===e.ConfigurationTarget.Global,n=e.window.createQuickPick(),i=b(),l=["always","smart","onlyWithFlag","disabled"].map(r=>({state:r,label:M[r],description:$[r],alwaysShow:!0}));i!=="disabled"&&l.unshift({setTempDisabled:!u,label:u?K:H,alwaysShow:!0}),n.items=l,n.activeItems=u?[l[0]]:n.items.filter(r=>"state"in r&&r.state===i),n.title=J,n.placeholder=o?D:C,n.buttons=[{iconPath:new e.ThemeIcon(o?"folder":"globe"),tooltip:o?C:D}],n.show();let c=await new Promise(r=>{n.onDidAccept(()=>r(n.selectedItems[0])),n.onDidHide(()=>r(void 0)),n.onDidTriggerButton(()=>{r({scope:o?e.ConfigurationTarget.Workspace:e.ConfigurationTarget.Global})})});if(n.dispose(),!!c){if("scope"in c)return await G(t,c.scope);"state"in c&&(c.state!==i?s.update(g,c.state,a):u&&(c={setTempDisabled:!1})),"setTempDisabled"in c&&(v(t,i,!0),u=c.setTempDisabled,c.setTempDisabled?await y():await h(t),v(t,i,!1))}}function b(){return e.workspace.getConfiguration(f).get(g)??"disabled"}async function Y(t){(p||await t.workspaceState.get(S))&&(await t.workspaceState.update(S,void 0),await e.commands.executeCommand("extension.js-debug.clearAutoAttachVariables"),await y())}async function h(t){let a=await et(t);if(a)return p=Z(a).catch(async s=>{if(console.error("[debug-auto-launch] Error creating auto attach server: ",s),process.platform!=="win32")try{await w.promises.access((0,_.dirname)(a))}catch{console.error("[debug-auto-launch] Refreshing variables from error"),O();return}}),await p}var Z=async t=>{try{return await P(t)}catch{return await w.promises.unlink(t).catch(()=>{}),await P(t)}},P=t=>new Promise((a,s)=>{let o=(0,I.createServer)(n=>{let i=[];n.on("data",async l=>{if(l[l.length-1]!==0){i.push(l);return}i.push(l.slice(0,-1));try{await e.commands.executeCommand("extension.js-debug.autoAttachToProcess",JSON.parse(Buffer.concat(i).toString())),n.write(Buffer.from([0]))}catch(c){n.write(Buffer.from([1])),console.error(c)}})}).on("error",s).listen(t,()=>a(o))});async function y(){let t=await p;t&&await new Promise(a=>t.close(a))}var tt={async disabled(t){await Y(t)},async onlyWithFlag(t){await h(t)},async smart(t){await h(t)},async always(t){await h(t)}};function v(t,a,s=!1){if(a==="disabled"&&!s){d?.hide();return}d||(d=e.window.createStatusBarItem("status.debug.autoAttach",e.StatusBarAlignment.Left),d.name=e.l10n.t("Debug Auto Attach"),d.command=k,d.tooltip=e.l10n.t("Automatically attach to node.js processes in debug mode"),t.subscriptions.push(d));let o=s?"$(loading) ":"";o+=u?Q:X[a],d.text=o,d.show()}function A(t){T=T.then(async({context:a,state:s})=>t===s?{context:a,state:s}:(s!==null&&v(a,s,!0),await tt[t](a),u=!1,v(a,t,!1),{context:a,state:t}))}async function et(t){let a=t.workspaceState.get(S),s=e.extensions.getExtension("ms-vscode.js-debug-nightly")?.extensionPath||e.extensions.getExtension("ms-vscode.js-debug")?.extensionPath,o=at();if(a?.jsDebugPath===s&&a?.settingsValue===o)return a.ipcAddress;let n=await e.commands.executeCommand("extension.js-debug.setAutoAttachVariables",a?.ipcAddress);if(!n)return;let i=n.ipcAddress;return await t.workspaceState.update(S,{ipcAddress:i,jsDebugPath:s,settingsValue:o}),i}function at(){let t={},a=e.workspace.getConfiguration(f);for(let s of x)t[s]=a.get(s);return JSON.stringify(t)}0&&(module.exports={activate,deactivate});
//# sourceMappingURL=extension.js.map