提交 5c46e0d6 编写于 作者: M Matt Bierner

Extracting methods

上级 5efcb23d
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册