UNPKG

code-server

Version:

Run VS Code on a remote server.

6 lines (5 loc) • 25.8 kB
var ae=Object.create,A=Object.defineProperty,ce=Object.getPrototypeOf,de=Object.prototype.hasOwnProperty,le=Object.getOwnPropertyNames,me=Object.getOwnPropertyDescriptor;var G=n=>A(n,"__esModule",{value:!0});var ve=(n,e)=>{G(n);for(var t in e)A(n,t,{get:e[t],enumerable:!0})},ue=(n,e,t)=>{if(G(n),e&&typeof e=="object"||typeof e=="function")for(let o of le(e))!de.call(n,o)&&o!=="default"&&A(n,o,{get:()=>e[o],enumerable:!(t=me(e,o))||t.enumerable});return n},C=n=>n&&n.__esModule?n:ue(A(n!=null?ae(ce(n)):{},"default",{value:n,enumerable:!0}),n);ve(exports,{activate:()=>Ie});var g=C(require("vscode"));var h=C(require("vscode"));function S(n,e){let t=n.indexOf(e);t>=0&&n.splice(t,1)}function L(n){return n[n.length-1]}async function J(n,e){let t=await h.workspace.openTextDocument(n),o=t.getWordRangeAtPosition(e);return o||(o=t.getWordRangeAtPosition(e,/[^\s]+/)),Boolean(o)}function $(n,e,t=8,o=!0){let i=e.start.with({character:Math.max(0,e.start.character-t)}),s=n.getWordRangeAtPosition(i),r=n.getText(new h.Range(s?s.start:i,e.start)),a=n.getText(e),m=e.end.translate(0,331),D=n.getText(new h.Range(e.end,m));return o&&(r=r.replace(/^\s*/g,""),D=D.replace(/\s*$/g,"")),{before:r,inside:a,after:D}}var f=class{constructor(e){this.name=e}async set(e){await h.commands.executeCommand("setContext",this.name,e)}async reset(){await h.commands.executeCommand("setContext",this.name,void 0)}},W=class{constructor(e,t){this._doc=e;this._position=t;this._version=e.version,this._word=this._getAnchorWord(e,t)}_getAnchorWord(e,t){let o=e.getWordRangeAtPosition(t)||e.getWordRangeAtPosition(t,/[^\s]+/);return o&&e.getText(o)}guessedTrackedPosition(){if(!this._word)return this._position;if(this._version===this._doc.version)return this._position;let e=this._getAnchorWord(this._doc,this._position);if(this._word===e)return this._position;let t=this._position.line,o=0,i,s;do{if(s=!1,i=t+o,i<this._doc.lineCount){s=!0;let r=this._doc.lineAt(i).text.indexOf(this._word);if(r>=0)return new h.Position(i,r)}if(o+=1,i=t-o,i>=0){s=!0;let r=this._doc.lineAt(i).text.indexOf(this._word);if(r>=0)return new h.Position(i,r)}}while(o<100&&s);return this._position}},he=["symbol-file","symbol-module","symbol-namespace","symbol-package","symbol-class","symbol-method","symbol-property","symbol-field","symbol-constructor","symbol-enum","symbol-interface","symbol-function","symbol-variable","symbol-constant","symbol-string","symbol-number","symbol-boolean","symbol-array","symbol-object","symbol-key","symbol-null","symbol-enum-member","symbol-struct","symbol-event","symbol-operator","symbol-type-parameter"];function N(n){let e=he[n];return e?new h.ThemeIcon(e):void 0}var u=C(require("vscode"));var R=class{constructor(e,t){this.location=e;this.direction=t;this.contextValue="callHierarchy";this.title=t===T.Incoming?"Callers Of":"Calls From"}async resolve(){let e=await Promise.resolve(u.commands.executeCommand("vscode.prepareCallHierarchy",this.location.uri,this.location.range.start)),t=new X(this.direction,e!=null?e:[]),o=new Y(t);if(t.roots.length!==0)return{provider:o,get message(){return t.roots.length===0?"No results.":void 0},navigation:t,highlights:t,dispose(){o.dispose()}}}with(e){return new R(e,this.direction)}},T;(function(n){n[n.Incoming=0]="Incoming",n[n.Outgoing=1]="Outgoing"})(T||(T={}));var k=class{constructor(e,t,o,i){this.model=e;this.item=t;this.parent=o;this.locations=i}remove(){this.model.remove(this)}},X=class{constructor(e,t){this.direction=e;this.roots=[];this._onDidChange=new u.EventEmitter;this.onDidChange=this._onDidChange.event;this.roots=t.map(o=>new k(this,o,void 0,void 0))}async _resolveCalls(e){if(this.direction===0){let t=await u.commands.executeCommand("vscode.provideIncomingCalls",e.item);return t?t.map(o=>new k(this,o.from,e,o.fromRanges.map(i=>new u.Location(o.from.uri,i)))):[]}else{let t=await u.commands.executeCommand("vscode.provideOutgoingCalls",e.item);return t?t.map(o=>new k(this,o.to,e,o.fromRanges.map(i=>new u.Location(e.item.uri,i)))):[]}}async getCallChildren(e){return e.children||(e.children=await this._resolveCalls(e)),e.children}location(e){return new u.Location(e.item.uri,e.item.range)}nearest(e,t){var o;return(o=this.roots.find(i=>i.item.uri.toString()===e.toString()))!=null?o:this.roots[0]}next(e){var t;return(t=this._move(e,!0))!=null?t:e}previous(e){var t;return(t=this._move(e,!1))!=null?t:e}_move(e,t){var i,s;if((i=e.children)==null?void 0:i.length)return t?e.children[0]:L(e.children);let o=this.roots.includes(e)?this.roots:(s=e.parent)==null?void 0:s.children;if(o==null?void 0:o.length){let r=o.indexOf(e);return o[r+(t?1:-1)+o.length%o.length]}}getEditorHighlights(e,t){return e.locations?e.locations.filter(o=>o.uri.toString()===t.toString()).map(o=>o.range):e.item.uri.toString()===t.toString()?[e.item.selectionRange]:void 0}remove(e){var i;let o=this.roots.includes(e)?this.roots:(i=e.parent)==null?void 0:i.children;o&&(S(o,e),this._onDidChange.fire(this))}},Y=class{constructor(e){this._model=e;this._emitter=new u.EventEmitter;this.onDidChangeTreeData=this._emitter.event;this._modelListener=e.onDidChange(t=>this._emitter.fire(t instanceof k?t:void 0))}dispose(){this._emitter.dispose(),this._modelListener.dispose()}getTreeItem(e){let t=new u.TreeItem(e.item.name);return t.description=e.item.detail,t.contextValue="call-item",t.iconPath=N(e.item.kind),t.command={command:"vscode.open",title:"Open Call",arguments:[e.item.uri,{selection:e.item.selectionRange.with({end:e.item.selectionRange.start})}]},t.collapsibleState=u.TreeItemCollapsibleState.Collapsed,t}getChildren(e){return e?this._model.getCallChildren(e):this._model.roots}getParent(e){return e.parent}};function Z(n,e){let t=new B(e.workspaceState,T.Incoming);function o(){if(g.window.activeTextEditor){let s=new R(new g.Location(g.window.activeTextEditor.document.uri,g.window.activeTextEditor.selection.active),t.value);n.setInput(s)}}function i(s,r){t.value=s;let a,m=n.getInput();r instanceof k?a=new R(new g.Location(r.item.uri,r.item.selectionRange.start),t.value):m instanceof R&&(a=new R(m.location,t.value)),a&&n.setInput(a)}e.subscriptions.push(g.commands.registerCommand("references-view.showCallHierarchy",o),g.commands.registerCommand("references-view.showOutgoingCalls",s=>i(T.Outgoing,s)),g.commands.registerCommand("references-view.showIncomingCalls",s=>i(T.Incoming,s)),g.commands.registerCommand("references-view.removeCallItem",pe))}function pe(n){n instanceof k&&n.remove()}var M=class{constructor(e,t=T.Outgoing){this._mem=e;this._value=t;this._ctxMode=new f("references-view.callHierarchyMode");let o=e.get(M._key);typeof o=="number"&&o>=0&&o<=1?this.value=o:this.value=t}get value(){return this._value}set value(e){this._value=e,this._ctxMode.set(this._value===T.Incoming?"showIncoming":"showOutgoing"),this._mem.update(M._key,e)}},B=M;B._key="references-view.callHierarchyMode";var l=C(require("vscode"));var d=C(require("vscode"));var E=class{constructor(e,t,o,i){this.title=e;this.location=t;this._command=o;this._result=i;this.contextValue=o}async resolve(){let e;if(this._result)e=new b(this._result);else{let o=await Promise.resolve(d.commands.executeCommand(this._command,this.location.uri,this.location.range.start));e=new b(o!=null?o:[])}if(e.items.length===0)return;let t=new ee(e);return{provider:t,get message(){return e.message},navigation:e,highlights:e,dispose(){t.dispose()}}}with(e){return new E(this.title,e,this._command)}},b=class{constructor(e){this._onDidChange=new d.EventEmitter;this.onDidChangeTreeData=this._onDidChange.event;this.items=[];let t;for(let o of e.sort(b._compareLocations)){let i=o instanceof d.Location?o:new d.Location(o.targetUri,o.targetRange);(!t||b._compareUriIgnoreFragment(t.uri,i.uri)!==0)&&(t=new y(i.uri.with({fragment:""}),[],this),this.items.push(t)),t.references.push(new _(i,t))}}static _compareUriIgnoreFragment(e,t){let o=e.with({fragment:""}).toString(),i=t.with({fragment:""}).toString();return o<i?-1:o>i?1:0}static _compareLocations(e,t){let o=e instanceof d.Location?e.uri:e.targetUri,i=t instanceof d.Location?t.uri:t.targetUri;if(o.toString()<i.toString())return-1;if(o.toString()>i.toString())return 1;let s=e instanceof d.Location?e.range:e.targetRange,r=t instanceof d.Location?t.range:t.targetRange;return s.start.isBefore(r.start)?-1:s.start.isAfter(r.start)?1:0}get message(){if(this.items.length===0)return"No results.";let e=this.items.reduce((o,i)=>o+i.references.length,0),t=this.items.length;return e===1&&t===1?`${e} result in ${t} file`:e===1?`${e} result in ${t} files`:t===1?`${e} results in ${t} file`:`${e} results in ${t} files`}location(e){return e instanceof _?e.location:void 0}nearest(e,t){if(this.items.length===0)return;for(let s of this.items)if(s.uri.toString()===e.toString()){for(let a of s.references)if(a.location.range.contains(t))return a;let r;for(let a of s.references){if(a.location.range.end.isAfter(t))return a;r=a}if(r)return r;break}let o=0,i=b._prefixLen(this.items[o].toString(),e.toString());for(let s=1;s<this.items.length;s++)b._prefixLen(this.items[s].uri.toString(),e.toString())>i&&(o=s);return this.items[o].references[0]}static _prefixLen(e,t){let o=0;for(;o<e.length&&o<t.length&&e.charCodeAt(o)===t.charCodeAt(o);)o+=1;return o}next(e){var t;return(t=this._move(e,!0))!=null?t:e}previous(e){var t;return(t=this._move(e,!1))!=null?t:e}_move(e,t){let o=t?1:-1,i=s=>{let r=(this.items.indexOf(s)+o+this.items.length)%this.items.length;return this.items[r]};if(e instanceof y)return t?i(e).references[0]:L(i(e).references);if(e instanceof _){let s=e.file.references.indexOf(e)+o;return s<0?L(i(e.file).references):s>=e.file.references.length?i(e.file).references[0]:e.file.references[s]}}getEditorHighlights(e,t){let o=this.items.find(i=>i.uri.toString()===t.toString());return o==null?void 0:o.references.map(i=>i.location.range)}remove(e){e instanceof y?(S(this.items,e),this._onDidChange.fire(void 0)):(S(e.file.references,e),e.file.references.length===0?(S(this.items,e.file),this._onDidChange.fire(void 0)):this._onDidChange.fire(e.file))}async asCopyText(){let e="";for(let t of this.items)e+=`${await t.asCopyText()} `;return e}},ee=class{constructor(e){this._model=e;this._onDidChange=new d.EventEmitter;this.onDidChangeTreeData=this._onDidChange.event;this._listener=e.onDidChangeTreeData(t=>this._onDidChange.fire(void 0))}dispose(){this._onDidChange.dispose(),this._listener.dispose()}async getTreeItem(e){if(e instanceof y){let t=new d.TreeItem(e.uri);return t.contextValue="file-item",t.description=!0,t.iconPath=d.ThemeIcon.File,t.collapsibleState=d.TreeItemCollapsibleState.Collapsed,t}else{let{range:t}=e.location,o=await e.getDocument(!0),{before:i,inside:s,after:r}=$(o,t),a={label:i+s+r,highlights:[[i.length,i.length+s.length]]},m=new d.TreeItem(a);return m.collapsibleState=d.TreeItemCollapsibleState.None,m.contextValue="reference-item",m.command={command:"vscode.open",title:"Open Reference",arguments:[e.location.uri,{selection:t.with({end:t.start})}]},m}}async getChildren(e){if(!e)return this._model.items;if(e instanceof y)return e.references}getParent(e){return e instanceof _?e.file:void 0}},y=class{constructor(e,t,o){this.uri=e;this.references=t;this.model=o}remove(){this.model.remove(this)}async asCopyText(){let e=`${d.workspace.asRelativePath(this.uri)} `;for(let t of this.references)e+=` ${await t.asCopyText()} `;return e}},_=class{constructor(e,t){this.location=e;this.file=t}async getDocument(e){if(this._document||(this._document=d.workspace.openTextDocument(this.location.uri)),e){let t=this.file.model.next(this.file);t instanceof y&&t!==this.file?d.workspace.openTextDocument(t.uri):t instanceof _&&d.workspace.openTextDocument(t.location.uri)}return this._document}remove(){this.file.model.remove(this)}async asCopyText(){let e=await this.getDocument(),t=$(e,this.location.range,21,!1);return`${this.location.range.start.line+1}, ${this.location.range.start.character+1}: ${t.before+t.inside+t.after}`}};function te(n,e){function t(r,a){if(l.window.activeTextEditor){let m=new E(r,new l.Location(l.window.activeTextEditor.document.uri,l.window.activeTextEditor.selection.active),a);n.setInput(m)}}e.subscriptions.push(l.commands.registerCommand("references-view.findReferences",()=>t("References","vscode.executeReferenceProvider")),l.commands.registerCommand("references-view.findImplementations",()=>t("Implementations","vscode.executeImplementationProvider")),l.commands.registerCommand("references-view.find",(...r)=>l.commands.executeCommand("references-view.findReferences",...r)),l.commands.registerCommand("references-view.removeReferenceItem",ge),l.commands.registerCommand("references-view.copy",K),l.commands.registerCommand("references-view.copyAll",fe),l.commands.registerCommand("references-view.copyPath",ye));let o,i="references.preferredLocation";function s(r){if(r&&!r.affectsConfiguration(i))return;let a=l.workspace.getConfiguration().get(i);o==null||o.dispose(),o=void 0,a==="view"&&(o=l.commands.registerCommand("editor.action.showReferences",async(m,D,F)=>{let O=new E("References",new l.Location(m,D),"vscode.executeReferenceProvider",F);n.setInput(O)}))}e.subscriptions.push(l.workspace.onDidChangeConfiguration(s)),e.subscriptions.push({dispose:()=>o==null?void 0:o.dispose()}),s()}var fe=async n=>{n instanceof _?K(n.file.model):n instanceof y&&K(n.model)};function ge(n){(n instanceof y||n instanceof _)&&n.remove()}async function K(n){let e;n instanceof b?e=await n.asCopyText():n instanceof _?e=await n.asCopyText():n instanceof y&&(e=await n.asCopyText()),e&&await l.env.clipboard.writeText(e)}async function ye(n){n instanceof y&&(n.uri.scheme==="file"?l.env.clipboard.writeText(n.uri.fsPath):l.env.clipboard.writeText(n.uri.toString(!0)))}var c=C(require("vscode"));var v=C(require("vscode")),j=class{constructor(e,t){this._view=e;this._delegate=t;this._decorationType=v.window.createTextEditorDecorationType({backgroundColor:new v.ThemeColor("editor.findMatchHighlightBackground"),rangeBehavior:v.DecorationRangeBehavior.ClosedClosed,overviewRulerLane:v.OverviewRulerLane.Center,overviewRulerColor:new v.ThemeColor("editor.findMatchHighlightBackground")});this.disposables=[];this._ignore=new Set;this.disposables.push(v.workspace.onDidChangeTextDocument(o=>this._ignore.add(o.document.uri.toString())),v.window.onDidChangeActiveTextEditor(()=>e.visible&&this.update()),e.onDidChangeVisibility(o=>o.visible?this._show():this._hide()),e.onDidChangeSelection(()=>e.visible&&this.update())),this._show()}dispose(){v.Disposable.from(...this.disposables).dispose();for(let e of v.window.visibleTextEditors)e.setDecorations(this._decorationType,[])}_show(){let{activeTextEditor:e}=v.window;if(!e||!e.viewColumn||this._ignore.has(e.document.uri.toString()))return;let[t]=this._view.selection;if(!t)return;let o=this._delegate.getEditorHighlights(t,e.document.uri);o&&e.setDecorations(this._decorationType,o)}_hide(){for(let e of v.window.visibleTextEditors)e.setDecorations(this._decorationType,[])}update(){this._hide(),this._show()}};var w=C(require("vscode"));var q=class{constructor(e){this._view=e;this._disposables=[];this._ctxCanNavigate=new f("references-view.canNavigate");this._disposables.push(w.commands.registerCommand("references-view.next",()=>this.next(!1)),w.commands.registerCommand("references-view.prev",()=>this.previous(!1)))}dispose(){w.Disposable.from(...this._disposables).dispose()}update(e){this._delegate=e,this._ctxCanNavigate.set(Boolean(this._delegate))}_anchor(){if(!this._delegate)return;let[e]=this._view.selection;if(e)return e;if(!!w.window.activeTextEditor)return this._delegate.nearest(w.window.activeTextEditor.document.uri,w.window.activeTextEditor.selection.active)}_open(e,t){w.commands.executeCommand("vscode.open",e.uri,{selection:new w.Selection(e.range.start,e.range.start),preserveFocus:t})}previous(e){if(!this._delegate)return;let t=this._anchor();if(!t)return;let o=this._delegate.previous(t),i=this._delegate.location(o);i&&(this._view.reveal(o,{select:!0,focus:!0}),this._open(i,e))}next(e){if(!this._delegate)return;let t=this._anchor();if(!t)return;let o=this._delegate.next(t),i=this._delegate.location(o);i&&(this._view.reveal(o,{select:!0,focus:!0}),this._open(i,e))}};var z=class{constructor(){this.viewId="references-view.tree";this._ctxIsActive=new f("reference-list.isActive");this._ctxHasResult=new f("reference-list.hasResult");this._ctxInputSource=new f("reference-list.source");this._history=new ie(this);this._provider=new oe;this._tree=c.window.createTreeView(this.viewId,{treeDataProvider:this._provider,showCollapseAll:!0}),this._navigation=new q(this._tree)}dispose(){var e;this._history.dispose(),this._tree.dispose(),(e=this._sessionDisposable)==null||e.dispose()}getInput(){return this._input}async setInput(e){var m,D;if(!await J(e.location.uri,e.location.range.start)){this.clearInput();return}this._ctxInputSource.set(e.contextValue),this._ctxIsActive.set(!0),this._ctxHasResult.set(!0),c.commands.executeCommand(`${this.viewId}.focus`);let t=!this._input||Object.getPrototypeOf(this._input)!==Object.getPrototypeOf(e);this._input=e,(m=this._sessionDisposable)==null||m.dispose(),this._tree.title=e.title,this._tree.message=t?void 0:this._tree.message;let o=Promise.resolve(e.resolve());this._provider.update(o.then(F=>{var O;return(O=F==null?void 0:F.provider)!=null?O:this._history}));let i=await o;if(this._input!==e)return;if(!i){this.clearInput();return}this._history.add(e),this._tree.message=i.message,this._navigation.update(i.navigation);let s=(D=i.navigation)==null?void 0:D.nearest(e.location.uri,e.location.range.start);s&&this._tree.visible&&await this._tree.reveal(s,{select:!0,focus:!0,expand:!0});let r=[],a;i.highlights&&(a=new j(this._tree,i.highlights),r.push(a)),i.provider.onDidChangeTreeData&&r.push(i.provider.onDidChangeTreeData(()=>{this._tree.title=e.title,this._tree.message=i.message,a==null||a.update()})),typeof i.dispose=="function"&&r.push(new c.Disposable(()=>i.dispose())),this._sessionDisposable=c.Disposable.from(...r)}clearInput(){var e;(e=this._sessionDisposable)==null||e.dispose(),this._input=void 0,this._ctxHasResult.set(!1),this._ctxInputSource.reset(),this._tree.title="References",this._tree.message=this._history.size===0?"No results.":"No results. Try running a previous search again:",this._provider.update(Promise.resolve(this._history))}},oe=class{constructor(){this._onDidChange=new c.EventEmitter;this.onDidChangeTreeData=this._onDidChange.event}update(e){var t;(t=this._sessionDispoables)==null||t.dispose(),this._sessionDispoables=void 0,this._onDidChange.fire(void 0),this.provider=e,e.then(o=>{this.provider===e&&o.onDidChangeTreeData&&(this._sessionDispoables=o.onDidChangeTreeData(this._onDidChange.fire,this._onDidChange))}).catch(o=>{this.provider=void 0,console.error(o)})}async getTreeItem(e){return this._assertProvider(),(await this.provider).getTreeItem(e)}async getChildren(e){return this._assertProvider(),(await this.provider).getChildren(e)}async getParent(e){this._assertProvider();let t=await this.provider;return t.getParent?t.getParent(e):void 0}_assertProvider(){if(!this.provider)throw new Error("MISSING provider")}},V=class{constructor(e,t,o,i){this.key=e;this.word=t;this.anchor=o;this.input=i;this.description=`${c.workspace.asRelativePath(i.location.uri)} \u2022 ${i.title.toLocaleLowerCase()}`}},ie=class{constructor(e){this._tree=e;this._onDidChangeTreeData=new c.EventEmitter;this.onDidChangeTreeData=this._onDidChangeTreeData.event;this._disposables=[];this._ctxHasHistory=new f("reference-list.hasHistory");this._inputs=new Map;this._disposables.push(c.commands.registerCommand("references-view.clear",()=>e.clearInput()),c.commands.registerCommand("references-view.clearHistory",()=>{this.clear(),e.clearInput()}),c.commands.registerCommand("references-view.refind",t=>{t instanceof V&&this._reRunHistoryItem(t)}),c.commands.registerCommand("references-view.refresh",()=>{let t=Array.from(this._inputs.values()).pop();t&&this._reRunHistoryItem(t)}),c.commands.registerCommand("_references-view.showHistoryItem",t=>{var o;if(t instanceof V){let i=(o=t.anchor.guessedTrackedPosition())!=null?o:t.input.location.range.start;return c.commands.executeCommand("vscode.open",t.input.location.uri,{selection:new c.Range(i,i)})}}),c.commands.registerCommand("references-view.pickFromHistory",async()=>{let o=(await this.getChildren()).map(s=>({label:s.word,description:s.description,item:s})),i=await c.window.showQuickPick(o,{placeHolder:"Select previous reference search"});i&&this._reRunHistoryItem(i.item)}))}dispose(){c.Disposable.from(...this._disposables).dispose(),this._onDidChangeTreeData.dispose()}_reRunHistoryItem(e){this._inputs.delete(e.key);let t=e.anchor.guessedTrackedPosition(),o=e.input;t&&!e.input.location.range.start.isEqual(t)&&(o=e.input.with(new c.Location(e.input.location.uri,t))),this._tree.setInput(o)}async add(e){var a,m;let t=await c.workspace.openTextDocument(e.location.uri),o=new W(t,e.location.range.start),i=(a=t.getWordRangeAtPosition(e.location.range.start))!=null?a:t.getWordRangeAtPosition(e.location.range.start,/[^\s]+/),s=i?t.getText(i):"???",r=new V(JSON.stringify([(m=i==null?void 0:i.start)!=null?m:e.location.range.start,e.location.uri,e.title]),s,o,e);this._inputs.delete(r.key),this._inputs.set(r.key,r),this._ctxHasHistory.set(!0)}clear(){this._inputs.clear(),this._ctxHasHistory.set(!1),this._onDidChangeTreeData.fire(void 0)}get size(){return this._inputs.size}getTreeItem(e){let t=new c.TreeItem(e.word);return t.description=e.description,t.command={command:"_references-view.showHistoryItem",arguments:[e],title:"Rerun"},t.collapsibleState=c.TreeItemCollapsibleState.None,t.contextValue="history-item",t}getChildren(){return Promise.all([...this._inputs.values()].reverse())}getParent(){}};var I=C(require("vscode"));var p=C(require("vscode"));var P=class{constructor(e,t){this.location=e;this.direction=t;this.contextValue="typeHierarchy";this.title=t===x.Supertypes?"Supertypes Of":"Subtypes Of"}async resolve(){let e=await Promise.resolve(p.commands.executeCommand("vscode.prepareTypeHierarchy",this.location.uri,this.location.range.start)),t=new ne(this.direction,e!=null?e:[]),o=new se(t);if(t.roots.length!==0)return{provider:o,get message(){return t.roots.length===0?"No results.":void 0},navigation:t,highlights:t,dispose(){o.dispose()}}}with(e){return new P(e,this.direction)}},x;(function(n){n.Subtypes="subtypes",n.Supertypes="supertypes"})(x||(x={}));var H=class{constructor(e,t,o){this.model=e;this.item=t;this.parent=o}remove(){this.model.remove(this)}},ne=class{constructor(e,t){this.direction=e;this.roots=[];this._onDidChange=new p.EventEmitter;this.onDidChange=this._onDidChange.event;this.roots=t.map(o=>new H(this,o,void 0))}async _resolveTypes(e){if(this.direction===x.Supertypes){let t=await p.commands.executeCommand("vscode.provideSupertypes",e.item);return t?t.map(o=>new H(this,o,e)):[]}else{let t=await p.commands.executeCommand("vscode.provideSubtypes",e.item);return t?t.map(o=>new H(this,o,e)):[]}}async getTypeChildren(e){return e.children||(e.children=await this._resolveTypes(e)),e.children}location(e){return new p.Location(e.item.uri,e.item.range)}nearest(e,t){var o;return(o=this.roots.find(i=>i.item.uri.toString()===e.toString()))!=null?o:this.roots[0]}next(e){var t;return(t=this._move(e,!0))!=null?t:e}previous(e){var t;return(t=this._move(e,!1))!=null?t:e}_move(e,t){var i,s;if((i=e.children)==null?void 0:i.length)return t?e.children[0]:L(e.children);let o=this.roots.includes(e)?this.roots:(s=e.parent)==null?void 0:s.children;if(o==null?void 0:o.length){let r=o.indexOf(e);return o[r+(t?1:-1)+o.length%o.length]}}getEditorHighlights(e,t){return e.item.uri.toString()===t.toString()?[e.item.selectionRange]:void 0}remove(e){var i;let o=this.roots.includes(e)?this.roots:(i=e.parent)==null?void 0:i.children;o&&(S(o,e),this._onDidChange.fire(this))}},se=class{constructor(e){this._model=e;this._emitter=new p.EventEmitter;this.onDidChangeTreeData=this._emitter.event;this._modelListener=e.onDidChange(t=>this._emitter.fire(t instanceof H?t:void 0))}dispose(){this._emitter.dispose(),this._modelListener.dispose()}getTreeItem(e){let t=new p.TreeItem(e.item.name);return t.description=e.item.detail,t.contextValue="type-item",t.iconPath=N(e.item.kind),t.command={command:"vscode.open",title:"Open Type",arguments:[e.item.uri,{selection:e.item.selectionRange.with({end:e.item.selectionRange.start})}]},t.collapsibleState=p.TreeItemCollapsibleState.Collapsed,t}getChildren(e){return e?this._model.getTypeChildren(e):this._model.roots}getParent(e){return e.parent}};function re(n,e){let t=new Q(e.workspaceState,x.Subtypes);function o(){if(I.window.activeTextEditor){let s=new P(new I.Location(I.window.activeTextEditor.document.uri,I.window.activeTextEditor.selection.active),t.value);n.setInput(s)}}function i(s,r){t.value=s;let a,m=n.getInput();r instanceof H?a=new P(new I.Location(r.item.uri,r.item.selectionRange.start),t.value):m instanceof P&&(a=new P(m.location,t.value)),a&&n.setInput(a)}e.subscriptions.push(I.commands.registerCommand("references-view.showTypeHierarchy",o),I.commands.registerCommand("references-view.showSupertypes",s=>i(x.Supertypes,s)),I.commands.registerCommand("references-view.showSubtypes",s=>i(x.Subtypes,s)),I.commands.registerCommand("references-view.removeTypeItem",we))}function we(n){n instanceof H&&n.remove()}var U=class{constructor(e,t=x.Subtypes){this._mem=e;this._value=t;this._ctxMode=new f("references-view.typeHierarchyMode");let o=e.get(U._key);typeof o=="string"?this.value=o:this.value=t}get value(){return this._value}set value(e){this._value=e,this._ctxMode.set(e),this._mem.update(U._key,e)}},Q=U;Q._key="references-view.typeHierarchyMode";function Ie(n){let e=new z;te(e,n),Z(e,n),re(e,n);function t(o){e.setInput(o)}return{setInput:t}} //# sourceMappingURL=extension.js.map