@@ -11,7 +11,8 @@ import {
1111 OnTypeFormattingEditProvider , RenameProvider , DocumentSymbolProvider , DocumentLinkProvider , DeclarationProvider , ImplementationProvider ,
1212 DocumentColorProvider , SelectionRangeProvider , TypeDefinitionProvider , CallHierarchyProvider , LinkedEditingRangeProvider , TypeHierarchyProvider , WorkspaceSymbolProvider ,
1313 ProviderResult , TextEdit as VTextEdit , InlineCompletionItemProvider , EventEmitter , type TabChangeEvent , TabInputText , TabInputTextDiff , TabInputCustom ,
14- TabInputNotebook , type LogOutputChannel } from 'vscode' ;
14+ TabInputNotebook , type LogOutputChannel , type TextEditor
15+ } from 'vscode' ;
1516
1617import {
1718 RAL , Message , MessageSignature , Logger , ResponseError , RequestType0 , RequestType , NotificationType0 , NotificationType ,
@@ -48,8 +49,7 @@ import * as UUID from './utils/uuid';
4849import { ProgressPart } from './progressPart' ;
4950import {
5051 DynamicFeature , ensure , FeatureClient , LSPCancellationError , TextDocumentSendFeature , RegistrationData , StaticFeature ,
51- TextDocumentProviderFeature , WorkspaceProviderFeature ,
52- type TabsModel
52+ TextDocumentProviderFeature , WorkspaceProviderFeature , type VisibleDocuments
5353} from './features' ;
5454
5555import { DiagnosticFeature , DiagnosticProviderMiddleware , DiagnosticProviderShape , $DiagnosticPullOptions , DiagnosticFeatureShape } from './diagnostic' ;
@@ -498,25 +498,23 @@ export enum ShutdownMode {
498498 * diagnostics we need to de-dupe tabs that show the same resources since
499499 * we pull on the model not the UI.
500500 */
501- class Tabs implements TabsModel {
501+ class VisibleDocumentsImpl implements VisibleDocuments {
502502
503503 private open : Set < string > ;
504504 private readonly _onOpen : EventEmitter < Set < Uri > > ;
505505 private readonly _onClose : EventEmitter < Set < Uri > > ;
506- private readonly disposable : Disposable ;
506+ private readonly disposables : Disposable [ ] ;
507507
508508 constructor ( ) {
509+ this . disposables = [ ] ;
509510 this . open = new Set ( ) ;
510511 this . _onOpen = new EventEmitter ( ) ;
511512 this . _onClose = new EventEmitter ( ) ;
512- Tabs . fillTabResources ( this . open ) ;
513- const openTabsHandler = ( event : TabChangeEvent ) => {
514- if ( event . closed . length === 0 && event . opened . length === 0 ) {
515- return ;
516- }
513+ VisibleDocumentsImpl . fillVisibleResources ( this . open ) ;
514+ const updateVisibleDocuments = ( ) => {
517515 const oldTabs = this . open ;
518516 const currentTabs : Set < string > = new Set ( ) ;
519- Tabs . fillTabResources ( currentTabs ) ;
517+ VisibleDocumentsImpl . fillVisibleResources ( currentTabs ) ;
520518
521519 const closed : Set < string > = new Set ( ) ;
522520 const opened : Set < string > = new Set ( currentTabs ) ;
@@ -544,11 +542,16 @@ class Tabs implements TabsModel {
544542 }
545543 } ;
546544
547- if ( Window . tabGroups . onDidChangeTabs !== undefined ) {
548- this . disposable = Window . tabGroups . onDidChangeTabs ( openTabsHandler ) ;
549- } else {
550- this . disposable = { dispose : ( ) => { } } ;
551- }
545+ this . disposables . push ( Window . tabGroups . onDidChangeTabs ( ( event : TabChangeEvent ) => {
546+ if ( event . closed . length === 0 && event . opened . length === 0 ) {
547+ return ;
548+ }
549+ updateVisibleDocuments ( ) ;
550+ } ) ) ;
551+
552+ this . disposables . push ( Window . onDidChangeVisibleTextEditors ( ( _editors : readonly TextEditor [ ] ) => {
553+ updateVisibleDocuments ( ) ;
554+ } ) ) ;
552555 }
553556
554557 public get onClose ( ) : Event < Set < Uri > > {
@@ -560,7 +563,7 @@ class Tabs implements TabsModel {
560563 }
561564
562565 public dispose ( ) : void {
563- this . disposable . dispose ( ) ;
566+ this . disposables . forEach ( disposable => disposable . dispose ( ) ) ;
564567 }
565568
566569 public isActive ( document : TextDocument | Uri ) : boolean {
@@ -584,13 +587,13 @@ class Tabs implements TabsModel {
584587 return this . open . has ( uri . toString ( ) ) ;
585588 }
586589
587- public getTabResources ( ) : Set < Uri > {
590+ public getResources ( ) : Set < Uri > {
588591 const result : Set < Uri > = new Set ( ) ;
589- Tabs . fillTabResources ( new Set ( ) , result ) ;
592+ VisibleDocumentsImpl . fillVisibleResources ( new Set ( ) , result ) ;
590593 return result ;
591594 }
592595
593- private static fillTabResources ( strings : Set < string > | undefined , uris ?: Set < Uri > ) : void {
596+ private static fillVisibleResources ( strings : Set < string > | undefined , uris ?: Set < Uri > ) : void {
594597 const seen = strings ?? new Set ( ) ;
595598 for ( const group of Window . tabGroups . all ) {
596599 for ( const tab of group . tabs ) {
@@ -611,6 +614,14 @@ class Tabs implements TabsModel {
611614 }
612615 }
613616 }
617+ // Peek editors are not part of tabs but should be considered visible
618+ for ( const editor of Window . visibleTextEditors ) {
619+ const uri = editor . document . uri ;
620+ if ( ! seen . has ( uri . toString ( ) ) ) {
621+ seen . add ( uri . toString ( ) ) ;
622+ uris !== undefined && uris . add ( uri ) ;
623+ }
624+ }
614625 }
615626}
616627
@@ -668,7 +679,7 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
668679
669680 private readonly _c2p : c2p . Converter ;
670681 private readonly _p2c : p2c . Converter ;
671- private _tabsModel : TabsModel | undefined ;
682+ private _visibleDocuments : VisibleDocuments | undefined ;
672683
673684 public constructor ( id : string , name : string , clientOptions : LanguageClientOptions ) {
674685 this . _id = id ;
@@ -807,11 +818,11 @@ export abstract class BaseLanguageClient implements FeatureClient<Middleware, La
807818 return this . _c2p ;
808819 }
809820
810- public get tabsModel ( ) : TabsModel {
811- if ( this . _tabsModel === undefined ) {
812- this . _tabsModel = new Tabs ( ) ;
821+ public get visibleDocuments ( ) : VisibleDocuments {
822+ if ( this . _visibleDocuments === undefined ) {
823+ this . _visibleDocuments = new VisibleDocumentsImpl ( ) ;
813824 }
814- return this . _tabsModel ;
825+ return this . _visibleDocuments ;
815826 }
816827
817828 public get onTelemetry ( ) : Event < any > {
0 commit comments