提交 7ab79ffe 编写于 作者: M Matt Bierner

Extract getUri

上级 24d305ea
......@@ -27,28 +27,11 @@ export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbo
private readonly modeIds: string[]
) { }
public async provideWorkspaceSymbols(search: string, token: CancellationToken): Promise<SymbolInformation[]> {
// typescript wants to have a resource even when asking
// general questions so we check the active editor. If this
// doesn't match we take the first TS document.
let uri: Uri | undefined = undefined;
const editor = window.activeTextEditor;
if (editor) {
const document = editor.document;
if (document && this.modeIds.indexOf(document.languageId) >= 0) {
uri = document.uri;
}
}
if (!uri) {
const documents = workspace.textDocuments;
for (const document of documents) {
if (this.modeIds.indexOf(document.languageId) >= 0) {
uri = document.uri;
break;
}
}
}
public async provideWorkspaceSymbols(
search: string,
token: CancellationToken
): Promise<SymbolInformation[]> {
const uri = this.getUri();
if (!uri) {
return [];
}
......@@ -57,6 +40,7 @@ export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbo
if (!filepath) {
return [];
}
const args: Proto.NavtoRequestArgs = {
file: filepath,
searchValue: search
......@@ -85,4 +69,26 @@ export default class TypeScriptWorkspaceSymbolProvider implements WorkspaceSymbo
}
return label;
}
private getUri(): Uri | undefined {
// typescript wants to have a resource even when asking
// general questions so we check the active editor. If this
// doesn't match we take the first TS document.
const editor = window.activeTextEditor;
if (editor) {
const document = editor.document;
if (document && this.modeIds.indexOf(document.languageId) >= 0) {
return document.uri;
}
}
const documents = workspace.textDocuments;
for (const document of documents) {
if (this.modeIds.indexOf(document.languageId) >= 0) {
return document.uri;
}
}
return undefined;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册