Skip to content

Commit

Permalink
feat: Implement tabGroups api as it's used by the new LSP diagnostics…
Browse files Browse the repository at this point in the history
… protocol
  • Loading branch information
CGNonofr committed Jul 19, 2022
1 parent 617c3bc commit b1deb2a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import * as uri from 'vs/base/common/uri'
import customLanguages from './vscode-services/languages'
import customCommands from './vscode-services/commands'
import customWorkspace from './vscode-services/workspace'
import customWindow from './vscode-services/window'
import customWindow, { TextTabInput } from './vscode-services/window'
import customEnv from './vscode-services/env'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -173,7 +173,7 @@ const api: typeof vscode = {
DataTransferItem: unsupported,
LanguageStatusSeverity: extHostTypes.LanguageStatusSeverity,
QuickPickItemKind: extHostTypes.QuickPickItemKind,
TabInputText: unsupported,
TabInputText: TextTabInput,
TabInputTextDiff: unsupported,
TabInputCustom: unsupported,
TabInputNotebook: unsupported,
Expand Down
62 changes: 60 additions & 2 deletions src/vscode-services/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,41 @@ import { URI } from 'vs/base/common/uri'
import type * as vscode from 'vscode'
import { Event } from 'vs/base/common/event'
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes'
import { StandaloneServices } from 'vs/editor/standalone/browser/standaloneServices'
import { IModelService } from 'vs/editor/common/services/model'
import { DisposableStore } from 'vs/base/common/lifecycle'
import { ITextModel } from 'vs/editor/common/model'
import workspace from './workspace'
import { DEFAULT_EXTENSION, getExtHostServices } from './extHost'
import { Services } from '../services'
import { unsupported } from '../tools'

class TextTabInput {
constructor (readonly uri: URI) { }
}

function getTabFromModel (model: ITextModel, tabGroup: vscode.TabGroup): vscode.Tab {
return {
label: model.uri.fsPath,
group: tabGroup,
get isActive () { return model.isAttachedToEditor() },
isDirty: false,
isPinned: false,
isPreview: false,
input: new TextTabInput(model.uri)
}
}

const tabGroup: vscode.TabGroup = {
isActive: true,
activeTab: undefined,
viewColumn: extHostTypes.ViewColumn.One,
get tabs () {
const modelService = StandaloneServices.get(IModelService)
return modelService.getModels().map(model => getTabFromModel(model, tabGroup))
}
}

const window: typeof vscode.window = {
showInformationMessage (message: string, ...rest: Array<vscode.MessageOptions | string | vscode.MessageItem>) {
const { extHostMessageService } = getExtHostServices()
Expand Down Expand Up @@ -137,9 +167,37 @@ const window: typeof vscode.window = {
registerFileDecorationProvider: unsupported,
registerTerminalProfileProvider: unsupported,
onDidChangeTerminalState: Event.None,
get tabGroups () {
return unsupported()
tabGroups: {
get all () {
return [tabGroup]
},
activeTabGroup: tabGroup,
onDidChangeTabGroups: Event.None,
onDidChangeTabs (listener) {
const modelService = StandaloneServices.get(IModelService)
const store = new DisposableStore()
store.add(modelService.onModelAdded((model) => {
listener({
opened: [getTabFromModel(model, tabGroup)],
closed: [],
changed: []
})
}))
store.add(modelService.onModelRemoved((model) => {
listener({
opened: [],
closed: [getTabFromModel(model, tabGroup)],
changed: []
})
}))

return store
},
close: unsupported
}
}

export default window
export {
TextTabInput
}

0 comments on commit b1deb2a

Please sign in to comment.