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.", "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" "scope": "resource"
}, },
"typescript.workspaceSymbols.scope": {
"type": "string",
"enum": [
"allOpenProjects",
"currentProject"
],
"default": "allOpenProjects",
"scope": "window"
},
"javascript.showUnused": { "javascript.showUnused": {
"type": "boolean", "type": "boolean",
"default": true, "default": true,

View file

@ -8,6 +8,7 @@ import { workspace } from 'coc.nvim'
import * as Proto from '../protocol' import * as Proto from '../protocol'
import {ITypeScriptServiceClient} from '../typescriptService' import {ITypeScriptServiceClient} from '../typescriptService'
import * as typeConverters from '../utils/typeConverters' import * as typeConverters from '../utils/typeConverters'
import API from '../utils/api'
function getSymbolKind(item: Proto.NavtoItem): SymbolKind { function getSymbolKind(item: Proto.NavtoItem): SymbolKind {
switch (item.kind) { switch (item.kind) {
@ -38,15 +39,22 @@ export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbo
search: string, search: string,
token: CancellationToken token: CancellationToken
): Promise<SymbolInformation[]> { ): Promise<SymbolInformation[]> {
const uri = this.getUri()
if (!uri) return []
const filepath = this.client.toPath(uri) let filepath: string | undefined
if (!filepath) return [] 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 = { const args: Proto.NavtoRequestArgs = {
file: filepath, file: filepath,
searchValue: search searchValue: search,
maxResultCount: 256,
} }
const response = await this.client.execute('navto', args, token) const response = await this.client.execute('navto', args, token)
@ -93,4 +101,9 @@ export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbo
} }
return undefined return undefined
} }
private get searchAllOpenProjects(): boolean {
return this.client.apiVersion.gte(API.v390)
&& workspace.getConfiguration('typescript').get('workspaceSymbols.scope', 'allOpenProjects') === 'allOpenProjects'
}
} }