Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get whole CompletionItems that vscode provided in language service API "registerCompletionItemProvider"? #578

Closed
seanmcbreen opened this issue Nov 24, 2015 · 10 comments
Assignees
Milestone

Comments

@seanmcbreen
Copy link

From @BleyChen on November 10, 2015 6:57

I want to develop an extension for JavaScript Intellisense in VSCode , And now i meet an problem that when i call the API "registerCompletionItemProvider" in the following code , i can't get the whole completionItems that provided by the VSCode itself in method "provideCompletionItems",anyone can help me?

  vscode.languages.registerCompletionItemProvider("javascript",
{
    resolveCompletionItem(item:vscode.CompletionItem, token: vscode.CancellationToken): vscode.CompletionItem 
    {

       var completionItem1:vscode.CompletionItem = new vscode.CompletionItem("id");
       completionItem1.detail = "aaa";
       completionItem1.filterText = "aa";
       completionItem1.insertText = "aa";
       return completionItem1;
    }
    ,
    provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise<vscode.CompletionItem[]> 
    {
    // I want to get    completionItems that provided by the VSCode itself ,not like following code ,provided by myself. does any variable has stored completionItems.

        return new Promise((resolve, reject) => { 
        var completionItems:vscode.CompletionItem[] = [];
        var completionItem:vscode.CompletionItem = new vscode.CompletionItem("bb");
        completionItem.detail = "bde";
        completionItem.filterText = "bb";
        completionItem.insertText = "bb";
        completionItems.push(completionItem);
        return resolve(completionItems) ;
                    });
    }
})

Copied from original issue: Microsoft/vscode-extensionbuilders#89

@seanmcbreen
Copy link
Author

From @jrieken on November 10, 2015 14:48

unsure if i have understood your question correctly, but wrt provideCompletionItems and resolveCompletionItem note the following:

  1. VS Code will always call provideCompletionItems to get a list of all completions available at a position.
  2. If the provider implements the optional method resolveCompletionItem it will be invoked when a completion is selected in the completion list UI. You should fill in detail and documentation if it was too expensive to fill in for each item during step Open Source VS Code #1.

so, to just get completions it's enough to return an array of completion items from provideCompletionItems

@seanmcbreen
Copy link
Author

From @BleyChen on November 11, 2015 2:54

sorry ,maybe my description is not very clear ,as we know , when we write JavaScript Code in JS File ,it will pop up completion list, what I want to know is that whether I can get completion list provided by the VSCode itself in provideCompletionItems.

@seanmcbreen
Copy link
Author

From @BleyChen on November 13, 2015 3:53

jrieken, i have two questions as following
1# .i just want to know whether has an variable stored completion items that provided by the VSCode itself that i can use in method provideCompletionItems . (my extension need use completion item to get additional information) ,

2#. i found that resolveCompletionItem will be triggered only when completion item which is provided by myself was selected ,so i want to know whether resolveCompletionItem can be called when user select someone else completion item in completion list UI, thank you!

@seanmcbreen
Copy link
Author

From @jrieken on November 13, 2015 12:11

Sorry, you cannot do either. The item someone else provided, including those VSCode provides, cannot be access by someone at that time, also resolveCompletionItem will be called with items your provider created.

@seanmcbreen
Copy link
Author

From @BleyChen on November 17, 2015 8:27

jrieken, thanks your replay , and I want to ask your some questions as following:

class CompletionItem {
label: string;
kind: CompletionItemKind;
detail: string; //
documentation: string; //
sortText: string; //
filterText: string; //
insertText: string;
textEdit: TextEdit; //
constructor(label: string);
}

  1. CompletionItem has one property named textEdit ,do you know what's the function of this property?

  2. do you know whether the words in documentation property of completionitem can wrap , the following code that I write can't wrap in the UI and only show in one line ,if words is more longer it will be clipped.

             provideCompletionItems(document: vscode.TextDocument, position: vscode.Position,          token: vscode.CancellationToken): Promise<vscode.CompletionItem[]> 
    {
        return new Promise((resolve, reject) => { 
    
        var completionItems:vscode.CompletionItem[] = [];
        var completionItem:vscode.CompletionItem = new vscode.CompletionItem("id");
        completionItem.detail = "test javascript detail";
        completionItem.documentation = "mde\r\nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf nadfdsf";
        completionItem.filterText = "test";
        completionItem.insertText = "bb";
        completionItem.label = "test";
    

    })
    }
    image

@seanmcbreen
Copy link
Author

We also ave this issue and it's something we need to work on - but for now the message is cropped at one line. This hits people in the VSCode API a lot as well.

@seanmcbreen
Copy link
Author

F8 hitting F8 should give you more space if that works for your users?

@seanmcbreen
Copy link
Author

Actually sorry I lie that's for a diagnostic not a completion :(

@egamma egamma modified the milestone: Backlog Dec 10, 2015
@jrieken jrieken closed this as completed Dec 18, 2015
@jrieken
Copy link
Member

jrieken commented Dec 18, 2015

We have now API Commands for this

@BleyChen
Copy link

@jrieken which API Commands ,can you tell me ,thank you!

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants