Skip to content

Commit

Permalink
Expose more properties of quick pick & add workspace remove action
Browse files Browse the repository at this point in the history
  • Loading branch information
asmodeus812 committed Aug 21, 2024
1 parent d8e80ad commit e28b8f3
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 2024-08-20

- Add `CocAction('removeWorkspaceFolder')`.
- Expanded the quick pick API in typings

# 2024-08-12

- Added `coc.preferences.formatterExtension` configuration
Expand Down
15 changes: 15 additions & 0 deletions src/__tests__/handler/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,21 @@ describe('Workspace handler', () => {
expect(find).toBeDefined()
})

it('should remove workspace folder', async () => {
expect(() => {
handler.addWorkspaceFolder(__filename)
}).toThrow(Error)
expect(() => {
handler.addWorkspaceFolder(__filename)
}).toThrow(Error)
await helper.plugin.cocAction('addWorkspaceFolder', __dirname)
await helper.plugin.cocAction('removeWorkspaceFolder', __dirname)
let folders = workspace.workspaceFolderControl.workspaceFolders
let uri = URI.file(__dirname).toString()
let find = folders.find(o => o.uri === uri)
expect(find).toBeUndefined()
})

it('should check env on vim resized', async () => {
await events.fire('VimResized', [80, 80])
expect(workspace.env.columns).toBe(80)
Expand Down
7 changes: 7 additions & 0 deletions src/handler/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ export default class WorkspaceHandler {
workspace.workspaceFolderControl.addWorkspaceFolder(folder, true)
}

public removeWorkspaceFolder(folder: string): void {
if (!Is.string(folder)) throw TypeError(`folder should be string`)
folder = workspace.expand(folder)
if (!isDirectory(folder)) throw directoryNotExists(folder)
workspace.workspaceFolderControl.removeWorkspaceFolder(folder)
}

public async bufferCheck(): Promise<void> {
let doc = await workspace.document
if (!doc.attached) {
Expand Down
4 changes: 4 additions & 0 deletions src/model/quickpick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ export default class QuickPick<T extends QuickPickItem> {
return this.win?.winid
}

public get inputBox(): InputBox | undefined {
return this.input
}

public setCursor(index: number): void {
this.win?.setCursor(index, true)
}
Expand Down
1 change: 1 addition & 0 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default class Plugin {
this.addAction('rootPatterns', (bufnr: number) => this.handler.workspace.getRootPatterns(bufnr))
this.addAction('ensureDocument', () => this.handler.workspace.ensureDocument())
this.addAction('addWorkspaceFolder', (folder: string) => this.handler.workspace.addWorkspaceFolder(folder))
this.addAction('removeWorkspaceFolder', (folder: string) => this.handler.workspace.removeWorkspaceFolder(folder))
this.addAction('getConfig', (key: string) => this.handler.workspace.getConfiguration(key))
this.addAction('doAutocmd', (id: number, ...args: []) => this.handler.workspace.doAutocmd(id, args))
this.addAction('openLog', () => this.handler.workspace.openLog())
Expand Down
18 changes: 18 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9554,6 +9554,24 @@ declare module 'coc.nvim' {
* Undefined by default, which means the width is dynamically calculated.
*/
width: number | undefined
/**
* Represents the input prompt box field of the quickpick element
**/
readonly inputBox: InputBox | undefined
/**
* The current selection index, can be used to act on an item with onDidFinish, even
* if the item is not selected. The index corresponds to the .items or .activeItems
* arrays, and can be used to index into them
**/
readonly currIndex: number
/**
* The buffer for the popup element of the quick pick containing the .items to be selected
**/
readonly buffer: number
/**
* The window for the popup element of the quick pick containing the .items to be selected
**/
readonly winid: number | undefined
/**
* An event signaling when QuickPick closed, fired with selected items or null when canceled.
*/
Expand Down

0 comments on commit e28b8f3

Please sign in to comment.