import*as Common from"../common/common.js";import*as Formatter from"../formatter/formatter.js";import*as i18n from"../i18n/i18n.js";import*as QuickOpen from"../quick_open/quick_open.js";import*as UI from"../ui/ui.js";import{SourcesView}from"./SourcesView.js";const UIStrings={noFileSelected:"No file selected.",openAJavascriptOrCssFileToSee:"Open a JavaScript or CSS file to see symbols",noResultsFound:"No results found",goToSymbol:"Go to symbol"},str_=i18n.i18n.registerUIStrings("sources/OutlineQuickOpen.js",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_),i18nLazyString=i18n.i18n.getLazilyComputedLocalizedString.bind(void 0,str_);let outlineQuickOpenInstance;export class OutlineQuickOpen extends QuickOpen.FilteredListWidget.Provider{constructor(){super(),this._items=[],this._active=!1}static instance(e={forceNew:null}){const{forceNew:t}=e;return outlineQuickOpenInstance&&!t||(outlineQuickOpenInstance=new OutlineQuickOpen),outlineQuickOpenInstance}attach(){this._items=[],this._active=!1;const e=this._currentUISourceCode();e&&(this._active=Formatter.FormatterWorkerPool.formatterWorkerPool().outlineForMimetype(e.workingCopy(),e.contentType().canonicalMimeType(),this._didBuildOutlineChunk.bind(this)))}_didBuildOutlineChunk(e,t){this._items.push(...t),this.refresh()}itemCount(){return this._items.length}itemKeyAt(e){const t=this._items[e];return t.title+(t.subtitle?t.subtitle:"")}itemScoreAt(e,t){const i=this._items[e];return t.split("(")[0].toLowerCase()===i.title.toLowerCase()?1/(1+i.line):-i.line-1}renderItem(e,t,i,n){const o=this._items[e];i.textContent=o.title+(o.subtitle?o.subtitle:""),QuickOpen.FilteredListWidget.FilteredListWidget.highlightRanges(i,t),n.textContent=":"+(o.line+1)}selectItem(e,t){if(null===e)return;const i=this._currentUISourceCode();if(!i)return;const n=this._items[e].line;!isNaN(n)&&n>=0&&Common.Revealer.reveal(i.uiLocation(n,this._items[e].column))}_currentUISourceCode(){const e=UI.Context.Context.instance().flavor(SourcesView);return e?e.currentUISourceCode():null}notFoundText(){return this._currentUISourceCode()?this._active?i18nString(UIStrings.noResultsFound):i18nString(UIStrings.openAJavascriptOrCssFileToSee):i18nString(UIStrings.noFileSelected)}}QuickOpen.FilteredListWidget.registerProvider({prefix:"@",title:i18nLazyString(UIStrings.goToSymbol),provider:OutlineQuickOpen.instance});