opened
eamodio
username_0
- VSCode Version: `1.4.0-insider` e3758d2cdaae78082a08a45ae28ea1bed5f47e8c
- OS Version: `OS X El Capitan 10.11.6`

Steps to Reproduce:

Working on a PR for https://github.com/OmniSharp/omnisharp-vscode to add git CodeLens in addition to the references CodeLens. I've tried setting each (git vs references) as separate providers, and all in one provider, but since both types of CodeLens are asynchronously resolved the order of them is random -- as seen below:

![screen shot 2016-08-03 at 2 54 43 am](https://cloud.githubusercontent.com/assets/641685/17356491/bfd043fc-5925-11e6-9a31-7d0bbde83b53.png)

Is there any way to control the order of how multiple CodeLens will combine on a single line?

I should also mention that I tried changing the range associated with the CodeLens (one at the start of the line, the other at the end) but saw no difference either.

Any help would be greatly appreciated!
Is there anyway to control the order of multiple CodeLens per line?
issue
created
jrieken
username_1
Code lenses for a line should be [sorted](https://github.com/Microsoft/vscode/blob/master/src/vs/editor/contrib/codelens/browser/codelens.ts#L514) by the their start column... Unsure tho if that order remains during the resolve phase...
comment
created
jrieken
username_1
@username_0 Unrelated question: Why do you want to add this to the omnisharp extension and don't make a separate extension? I believe this is a very useful extension and everyone (not only omnisharp users) should benefit from this 👍
comment
created
jrieken
username_1
So, if I have a simple code lenses provider that adds something for a decoration for each `abc` occurrence things work.

```
    vscode.languages.registerCodeLensProvider({ pattern: '**/*.abc' }, {
        provideCodeLenses(document, token) {
            const result: vscode.CodeLens[] = [];
            let idx = -1;
            while ((idx = document.getText().indexOf('abc', idx + 1)) > 0) {
                const pos = document.positionAt(idx);
                const range = document.getWordRangeAtPosition(pos);
                result.push(new vscode.CodeLens(range, { title: `Command@${idx}`, command: 'extension.sayHello' }));
            }
            return result;
        }
    });
```

<img width="433" alt="screen shot 2016-08-03 at 12 04 35" src="https://cloud.githubusercontent.com/assets/1794099/17361779/760077ae-5972-11e6-9563-e8603a6cb98a.png">


@username_0 Is it possible that the two providers create code lenses for the exact same range? Also, does one or both providers implement the `resolveCodeLens` method?
comment
created
eamodio
username_0
@username_1 Thanks for the response! I published my changes so I can reference them here, but fyi the code is a bit of a mess as I'm still just beginning and have been moving code around to try an 
d fix this issue.

Quick overview, I have 2 CodeLensProviders -- [`UsageCodeLensProvider`](https://github.com/username_0/omnisharp-vscode/blob/feature-git-code-lens/src/features/usagesCodeLensProvider.ts) and [`GitCodeLensProvider`](https://github.com/username_0/omnisharp-vscode/blob/feature-git-code-lens/src/features/gitCodeLensProvider.ts).

At first I had them both registered as independent providers with no communication between them. Then I had `UsagesCodeLensProvider` delegate to the other (basically created a promise that waited for both providers to resolve and then `concat`'d the resulting lens together -- with the Git ones last). Then I changed it to the code checked in -- adding both types of CodeLens basically in 1 provider. Still didn't work and then I tried playing with the range -- made the git CodeLens range [start after](https://github.com/username_0/omnisharp-vscode/blob/feature-git-code-lens/src/features/gitCodeLensProvider.ts#L78) the other and still didn't see any change.

As for the reasoning for adding this into the OmniSharp extension -- It was mainly laziness (not knowing how also). Since I knew that OmniSharp was already providing some CodeLens at the same points that I wanted to, I could piggyback on that. Even still I did start this as a separate extension, but I didn't want to have 2 copies of OmniSharp running and parsing the code (since I didn't know of anyway to share the same copy). And I also didn't (don't) know of a way to have vscode directly provide me a generic way of getting a type/interface declarations and method/properties for the languages so was unsure how to do this as a more general purpose extensions.  Though I completely agree it would be far preferable if possible (and without this extension from having to attempt to parse things itself).

Thanks again!
comment
created
jrieken
username_1
Ok, I understand how it ended up in the omnisharp extension... One could try to reuse the document symbol information but that might be a slippery slope... There is unfortunately no common ast nor reliable token information.

So, it's definitely favourable to have two separate providers. Since both use the same data source (`currentFileMemebersAsTree`) you will end up with the same ranges which isn't caught by our sorting. I see that you are modifying the [range](https://github.com/username_0/omnisharp-vscode/blob/feature-git-code-lens/src/features/gitCodeLensProvider.ts#L78) but beware that `Range` and `Position` is immutable meaning `with` won't modify but it create a *new* range instance that you should use. Then you should see an effect. 

On our side I'll work on a change to make sorting better when ranges equal (like sort by provider then).
comment
created
eamodio
username_0
@username_1 Ugh -- stupid mistake :( Thanks so much for your help. With that fixed I see the ordering is stable now. As for the document symbol information -- is there anything you can point me to there that I might explore?
comment
created
jrieken
username_1
What you could try is to utilise the `vscode.executeDocumentSymbolProvider` from here: https://code.visualstudio.com/docs/extensionAPI/vscode-api-commands. It basically what the UI would call to get the document symbols to render in the quick pick box. Be aware that the symbol kinds and ranges might slightly differ... Tho I believe its worth a try
comment
created
jrieken
username_1
Pushed a change that sorts by provider type in case ranges are equal.
comment
closed
jrieken
username_1
issue
created
jrieken
username_1
to verify have two provider like below and make sure that in a `foo.abc` file the `abc` text is annotated such that _2Command@n_ come before _Command@n_

```
    vscode.languages.registerCodeLensProvider({ pattern: '**/*.abc' }, {
        provideCodeLenses(document, token) {
            const result: vscode.CodeLens[] = [];
            let idx = -1;
            while ((idx = document.getText().indexOf('abc', idx + 1)) > 0) {
                const pos = document.positionAt(idx);
                const range = document.getWordRangeAtPosition(pos);
                result.push(new vscode.CodeLens(range, { title: `Command@${idx}`, command: 'extension.sayHello' }));
            }
            return result;
        }
    });

    vscode.languages.registerCodeLensProvider({ pattern: '**/*.abc' }, {
        provideCodeLenses(document, token) {
            const result: vscode.CodeLens[] = [];
            let idx = -1;
            while ((idx = document.getText().indexOf('abc', idx + 1)) > 0) {
                const pos = document.positionAt(idx);
                const range = document.getWordRangeAtPosition(pos);
                result.push(new vscode.CodeLens(range, { title: `2Command@${idx}`, command: 'extension.sayHello' }));
            }
            return result;
        }
    });
```
comment
created
aeschli
username_2
verifying...
comment
reopened
jrieken
username_1
- VSCode Version: `1.4.0-insider` e3758d2cdaae78082a08a45ae28ea1bed5f47e8c
- OS Version: `OS X El Capitan 10.11.6`

Steps to Reproduce:

Working on a PR for https://github.com/OmniSharp/omnisharp-vscode to add git CodeLens in addition to the references CodeLens. I've tried setting each (git vs references) as separate providers, and all in one provider, but since both types of CodeLens are asynchronously resolved the order of them is random -- as seen below:

![screen shot 2016-08-03 at 2 54 43 am](https://cloud.githubusercontent.com/assets/641685/17356491/bfd043fc-5925-11e6-9a31-7d0bbde83b53.png)

Is there any way to control the order of how multiple CodeLens will combine on a single line?

I should also mention that I tried changing the range associated with the CodeLens (one at the start of the line, the other at the end) but saw no difference either.

Any help would be greatly appreciated!
Is there anyway to control the order of multiple CodeLens per line?
issue
created
jrieken
username_1
<img width="410" alt="screen shot 2016-09-02 at 16 13 16" src="https://cloud.githubusercontent.com/assets/1794099/18206731/3ca048a4-7128-11e6-8b6c-3d203be8b74f.png">

Something is still wrong. Next try in September...
comment
closed
jrieken
username_1
issue
created
jrieken
username_1
Actually, not true. The two provider I use have different ranges
comment