Go to Symbol in workspace includes all opened projects

This commit is contained in:
Qiming Zhao 2020-06-20 11:21:33 +08:00
parent fde4e6cdd5
commit 031fa8f441
2 changed files with 32 additions and 10 deletions

View file

@ -409,6 +409,15 @@
"description": "Enable/disable showing completions on potentially undefined values that insert an optional chain call. Requires TS 3.7+ and strict null checks to be enabled.",
"scope": "resource"
},
"typescript.workspaceSymbols.scope": {
"type": "string",
"enum": [
"allOpenProjects",
"currentProject"
],
"default": "allOpenProjects",
"scope": "window"
},
"javascript.showUnused": {
"type": "boolean",
"default": true,

View file

@ -2,12 +2,13 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { CancellationToken, Range, SymbolInformation, SymbolKind } from 'vscode-languageserver-protocol'
import { WorkspaceSymbolProvider } from 'coc.nvim/lib/provider'
import { workspace } from 'coc.nvim'
import {CancellationToken, Range, SymbolInformation, SymbolKind} from 'vscode-languageserver-protocol'
import {WorkspaceSymbolProvider} from 'coc.nvim/lib/provider'
import {workspace} from 'coc.nvim'
import * as Proto from '../protocol'
import { ITypeScriptServiceClient } from '../typescriptService'
import {ITypeScriptServiceClient} from '../typescriptService'
import * as typeConverters from '../utils/typeConverters'
import API from '../utils/api'
function getSymbolKind(item: Proto.NavtoItem): SymbolKind {
switch (item.kind) {
@ -32,21 +33,28 @@ export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbo
public constructor(
private readonly client: ITypeScriptServiceClient,
private readonly languageIds: string[]
) { }
) {}
public async provideWorkspaceSymbols(
search: string,
token: CancellationToken
): Promise<SymbolInformation[]> {
const uri = this.getUri()
if (!uri) return []
const filepath = this.client.toPath(uri)
if (!filepath) return []
let filepath: string | undefined
if (this.searchAllOpenProjects) {
filepath = undefined
} else {
let uri = this.getUri()
filepath = uri ? this.client.toPath(uri) : undefined
if (!filepath && this.client.apiVersion.lt(API.v390)) {
return []
}
}
const args: Proto.NavtoRequestArgs = {
file: filepath,
searchValue: search
searchValue: search,
maxResultCount: 256,
}
const response = await this.client.execute('navto', args, token)
@ -93,4 +101,9 @@ export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbo
}
return undefined
}
private get searchAllOpenProjects(): boolean {
return this.client.apiVersion.gte(API.v390)
&& workspace.getConfiguration('typescript').get('workspaceSymbols.scope', 'allOpenProjects') === 'allOpenProjects'
}
}