mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 09:08:53 +01:00
Extracting methods
This commit is contained in:
@@ -71,14 +71,22 @@ export default class JsDocCompletionProvider implements CompletionItemProvider {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Only show the JSdoc completion when the everything before the cursor is whitespace
|
||||
// or could be the opening of a comment
|
||||
const line = document.lineAt(position.line).text;
|
||||
const prefix = line.slice(0, position.character);
|
||||
if (prefix.match(/^\s*$|\/\*\*\s*$|^\s*\/\*\*+\s*$/) === null) {
|
||||
if (!this.isValidCursorPosition(document, position)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!await this.isCommentableLocation(file, position, token)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [new JsDocCompletionItem(document, position, enableJsDocCompletions)];
|
||||
}
|
||||
|
||||
private async isCommentableLocation(
|
||||
file: string,
|
||||
position: Position,
|
||||
token: CancellationToken
|
||||
): Promise<boolean> {
|
||||
const args: Proto.FileRequestArgs = {
|
||||
file
|
||||
};
|
||||
@@ -86,8 +94,9 @@ export default class JsDocCompletionProvider implements CompletionItemProvider {
|
||||
this.client.execute('navtree', args, token),
|
||||
new Promise<Proto.NavTreeResponse>((resolve) => setTimeout(resolve, 250))
|
||||
]);
|
||||
|
||||
if (!response || !response.body) {
|
||||
return [];
|
||||
return false;
|
||||
}
|
||||
|
||||
const body = response.body;
|
||||
@@ -104,11 +113,15 @@ export default class JsDocCompletionProvider implements CompletionItemProvider {
|
||||
return tree.childItems ? tree.childItems.some(matchesPosition) : false;
|
||||
}
|
||||
|
||||
if (!matchesPosition(body)) {
|
||||
return [];
|
||||
}
|
||||
return matchesPosition(body);
|
||||
}
|
||||
|
||||
return [new JsDocCompletionItem(document, position, enableJsDocCompletions)];
|
||||
private isValidCursorPosition(document: TextDocument, position: Position): boolean {
|
||||
// Only show the JSdoc completion when the everything before the cursor is whitespace
|
||||
// or could be the opening of a comment
|
||||
const line = document.lineAt(position.line).text;
|
||||
const prefix = line.slice(0, position.character);
|
||||
return prefix.match(/^\s*$|\/\*\*\s*$|^\s*\/\*\*+\s*$/) !== null;
|
||||
}
|
||||
|
||||
public resolveCompletionItem(item: CompletionItem, _token: CancellationToken) {
|
||||
|
||||
Reference in New Issue
Block a user