Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Feature request: always display references #726

Closed
mattetti opened this issue Jan 16, 2017 · 12 comments
Closed

Feature request: always display references #726

mattetti opened this issue Jan 16, 2017 · 12 comments

Comments

@mattetti
Copy link
Contributor

mattetti commented Jan 16, 2017

This is probably a hard one but something that is super useful when writing C# in Visual Studio

The feature is defined here: https://code.visualstudio.com/docs/editor/editingevolved#_reference-information

VSCode supports this feature when asking for references of a specific value, but the data isn't cached and it isn't always displayed as in the image above.

https://code.visualstudio.com/Docs/extensionAPI/vscode-api#_a-namecodelensaspan-classcodeitem-id471codelensspan

@dz4va
Copy link

dz4va commented Jan 31, 2017

++ this is like a must have time saver to me.

@theSoenke
Copy link
Contributor

This would be really awesome. Codelens is also now available for Typescript https://code.visualstudio.com/updates/v1_9#_typescript-references-codelens It's has been a very useful feature for me in C# in VS

@ramya-rao-a
Copy link
Contributor

Yes, it is a very good feature indeed. PRs are welcome.

@theSoenke
Copy link
Contributor

I've build a go codelens prototype. It shows references for functions, interfaces and structs. It takes some time to find all references, but i don't think there is much i can do about it. https://github.com/thesoenke/vscode-go/tree/codelens

go-codelens

One issue i ran into is that go-outline seems to return always 1 as the start character instead as of at least 6 for functions in a line, but for structs it's correct.

Another issue is that the console is filled with errors from guru when editing the code. Not sure what's the best solution here

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Apr 17, 2017

@theSoenke great work! Please send a PR and we can try and get this in the next release :)

Few points

  • I have a case where a function is used in another Go project outside the workspace opened in VS Code. The Codelens lists this external reference, but when I do a "Find all references", the external reference is not listed. Any idea how that happened?
  • About go-outline returning different offset for func vs type, looks like that is how the Go parser works. See https://github.com/lukehoban/go-outline/blob/master/main.go#L53
  • About console filled with errors, I am looking into it

@ramya-rao-a
Copy link
Contributor

@theSoenke

About the errors in the console on edit, I see 2 types

  • guru failing. This I am looking into
  • Other one is

screen shot 2017-04-17 at 12 45 26 pm

The second one is because you are returning the codelens promises even the ones that do not return a codelens.

So something like this

let codelenses = [];
            return Promise.all(lenses).then(values => {
                values.forEach(lens => {
                    if (lens){
                        codelenses.push(lens);
                    }
                });
                return codelenses;
            });

instead of return Promise.all(lenses) will fix that.

@ramya-rao-a
Copy link
Contributor

@theSoenke Found the issue. Both guru and go-outline work only on saved files. Therefore, when you edit, all the positions get messed up. I'll fix that and this should work like a charm.

@ramya-rao-a
Copy link
Contributor

@theSoenke Alright, I have updated both go-outline and guru to use the -modified flag to work on unsaved file contents.

Merge from master, and things should work well now.

@theSoenke
Copy link
Contributor

Great! Thanks for looking so quick into this and provide the fixes 👋

Unfortunately the debug console still contains errors from guru when syntax is not valid and the file not saved.

@ramya-rao-a
Copy link
Contributor

Oh that! That is the call to references being cancelled.

Change the if (err) at https://github.com/theSoenke/vscode-go/blob/codelens/src/goReferences.ts#L44 to if (err && (<any>err).killed !== true, and you should be good to go

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented May 4, 2017

This feature is now available in the latest update (0.6.60).
It can be disabled by setting go.referencesCodeLens.enable to false

Thanks @theSoenke!

@theSoenke
Copy link
Contributor

Happy to contribute a little bit to this great extension :)

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 24, 2018
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

4 participants