Skip to content

Commit

Permalink
feat(list): add --buffer to list buffer diags (#4958)
Browse files Browse the repository at this point in the history
  • Loading branch information
fannheyward authored Mar 26, 2024
1 parent fb030d4 commit 9190bfe
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ about: Create a report to help us improve
<!--
**Warning: We will close the bug issue without the issue template and the reproduce ways.**
If you have question, please ask at https://gitter.im/neoclide/coc.nvim
If you have question, please ask at https://github.com/neoclide/coc.nvim/discussions
If the problem related to specific language server, please checkout: https://git.io/fjCEM
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<a href="https://github.com/neoclide/coc.nvim/actions"><img alt="Actions" src="https://img.shields.io/github/actions/workflow/status/neoclide/coc.nvim/ci.yml?style=flat-square&branch=master"></a>
<a href="https://codecov.io/gh/neoclide/coc.nvim"><img alt="Codecov Coverage Status" src="https://img.shields.io/codecov/c/github/neoclide/coc.nvim.svg?style=flat-square"></a>
<a href="doc/coc.txt"><img alt="Doc" src="https://img.shields.io/badge/doc-%3Ah%20coc.txt-brightgreen.svg?style=flat-square"></a>
<a href="https://matrix.to/#/#coc.nvim:matrix.org"><img alt="Gitter" src="https://img.shields.io/gitter/room/neoclide/coc.nvim.svg?style=flat-square"></a>
<a href="https://matrix.to/#/#coc.nvim:matrix.org"><img alt="Matrix" src="https://img.shields.io/matrix/coc.nvim%3Amatrix.org?style=flat-square"></a>
</p>
</p>

Expand Down
2 changes: 1 addition & 1 deletion autoload/coc/list.vim
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function! coc#list#setlines(bufnr, lines, append)
endfunction

function! coc#list#options(...)
let list = ['--top', '--tab', '--normal', '--no-sort', '--input=', '--strict',
let list = ['--top', '--tab', '--buffer', '--normal', '--no-sort', '--input=', '--strict',
\ '--regex', '--interactive', '--number-select', '--auto-preview',
\ '--ignore-case', '--no-quit', '--first', '--reverse', '--height=']
if get(g:, 'coc_enabled', 0)
Expand Down
17 changes: 17 additions & 0 deletions src/__tests__/list/sources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,9 +662,26 @@ describe('list sources', () => {

it('should load diagnostics source', async () => {
await createDocument('a')
await createDocument('b')
await manager.start(['diagnostics'])
await manager.session?.ui.ready
expect(manager.isActivated).toBe(true)

let buf = await nvim.buffer
let lines = await buf.lines
expect(lines.length).toEqual(10)
})

it('should load diagnostics for buffer only', async () => {
await createDocument('a')
await createDocument('b')
await manager.start(['diagnostics', '--buffer'])
await manager.session?.ui.ready
expect(manager.isActivated).toBe(true)

let buf = await nvim.buffer
let lines = await buf.lines
expect(lines.length).toEqual(5)
})

it('should refresh on diagnostics refresh', async () => {
Expand Down
15 changes: 13 additions & 2 deletions src/list/source/diagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
'use strict'
import { URI } from 'vscode-uri'
import diagnosticManager, { DiagnosticItem } from '../../diagnostic/manager'
import { defaultValue } from '../../util'
import { isParentFolder } from '../../util/fs'
import { path } from '../../util/node'
import workspace from '../../workspace'
import { formatListItems, formatPath, PathFormatting, UnformattedListItem } from '../formatting'
import { ListManager } from '../manager'
import { ListContext, ListItem } from '../types'
import { ListArgument, ListContext, ListItem } from '../types'
import LocationList from './location'

export function convertToLabel(item: DiagnosticItem, cwd: string, includeCode: boolean, pathFormat: PathFormatting = 'full'): string[] {
Expand All @@ -20,6 +22,11 @@ export default class DiagnosticsList extends LocationList {
public readonly defaultAction = 'open'
public readonly description = 'diagnostics of current workspace'
public name = 'diagnostics'
public options: ListArgument[] = [{
name: '--buffer',
hasValue: true,
description: 'list diagnostics of current buffer only',
}]
public constructor(manager: ListManager) {
super()
diagnosticManager.onDidRefresh(async () => {
Expand All @@ -30,7 +37,11 @@ export default class DiagnosticsList extends LocationList {

public async loadItems(context: ListContext): Promise<ListItem[]> {
let list = await diagnosticManager.getDiagnosticList()
let { cwd } = context
let { cwd, args } = context
if (args.includes('--buffer')) {
const doc = await workspace.document
list = list.filter(item => item.file === URI.parse(doc.uri).fsPath)
}
const config = this.getConfig()
const includeCode = config.get<boolean>('includeCode', true)
const pathFormat = config.get<PathFormatting>('pathFormat', "full")
Expand Down

0 comments on commit 9190bfe

Please sign in to comment.