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

Allow to query workspace/symbols by a SymbolDescriptor #12

Merged
merged 3 commits into from
Jan 17, 2017

Conversation

felixfbecker
Copy link

Use cases are constructing symbol URLs and global j2d.

Discussed with @rothfels and @beyang

@rothfels
Copy link

This LGTM, @beyang any comments?

### Extended Workspace Symbol Request

The `workspace/symbol` request takes an optional parameter `symbol` that allows you to query by known properties about the symbol.
The string `query` parameter becomes optional.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixfbecker think it might be good to give examples of the different use cases of query and symbol?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add an examples section.

/**
* Known properties about the symbol.
*/
symbol?: Partial<SymbolDescriptor>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we must modify the type of query to be optional with this extensive anyway, what is the reason to have the fields be separate?

i.e. why not just have query be either a string or a Partial<SymbolDescriptor> ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that too, but there are languages that are strictly typed and cannot have it either be a string or an object. LSP will avoid these union types in the future, see microsoft#39. There isn't really a disadvantage to it, but it increases the likelihood of the proposal getting accepted later.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

query symbol
user input in UI used programmatically
matches as fuzzily as possible matches as exact as possible
returns as many results as possible returns as few results as possible

Copy link
Member

@emidoots emidoots Jan 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, and sounds good. In that case:

  1. How about naming it querySymbol instead?
  2. Can we clarify that only one of query or querySymbol should be present? If not, what is the behavior of a LS when both are specified?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I like to keep it short and precise - if any, I would prefer symbolQuery, and that is kind of confusing since the whole thing you are doing is a symbol query. I thought about naming it symbolDescriptor, but it is not a full SymbolDescriptor, and I would like to change it to SymbolInformation soon.
  2. Yes, this should be specified. The semantics should be an AND, because it could be useful to query with a fuzzy query but restrict it to a specific SymbolKind or package.

@emidoots
Copy link
Member

The motivation behind this PR is to enable querying based on Sourcegraph URLs like sourcegraph.com/<repo>/<language/mode>/<language_specific_string> (e.g. sourcegraph.com/github.com/gorilla/mux/go/github.com/gorilla/mux/-/mux/-/Router/Serve for a Go example), right?

I assume it is. So the question arises: how does Sourcegraph know to get a SymbolDescriptor from a language-specific URL string? Will we need a language-specific Sourcegraph piece to do that?

If we would need a language-specific Sourcegraph piece to do this, why not just pass the string directly into the LS and let it parse it? e.g. we could change symbol type from Partial<SymbolDescriptor> to type string and say it's the LS responsibility to define/parse that string?

Copy link
Member

@emidoots emidoots left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(requesting changes so this doesn't get merged prematurely)

@felixfbecker
Copy link
Author

@slimsag The idea was to add a new field to SymbolDescriptor named id, and we would query by that to resolve the URL. The language server defines how it looks like, it just should be as unique as possible. This was the result of discussion with @beyang and @rothfels, since we need an endpoint to query by a SymbolDescriptor anyway later for global refs, it makes the most sense to add it now and use it to query by the symbol ID instead of adding new query parameters for every use case that will come up in the future. This is forward-compatible with #13.

@felixfbecker
Copy link
Author

TODO: need to add ServerCapability. Suggestions on the name welcome

@emidoots
Copy link
Member

emidoots commented Jan 16, 2017

since we need an endpoint to query by a SymbolDescriptor anyway later for global refs

Can you elaborate on this? Not sure if I understand which endpoint you are talking about

@emidoots
Copy link
Member

ServerCapability -> that is tricky, how about workspaceSymbolExact? (I don't feel strongly about this, just the best suggestion I can come up with)

@emidoots
Copy link
Member

Ok, I see why you'd want to pack id into SymbolDescriptor. That sounds logical / good to me. (I'd still like to understand your comment about the endpoint though, just to make sure I understand fully).

Copy link
Member

@emidoots emidoots left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@felixfbecker
Copy link
Author

since we need an endpoint to query by a SymbolDescriptor anyway later for global refs

Can you elaborate on this? Not sure if I understand which endpoint you are talking about

This was @beyang's point, I think it is needed because in TypeScript global j2d would normally not resolve to the actual declaration in the TS source, but to the TS definition file (which is just a stub). So I think the steps needed there are to do xdefinition, get the repository info, then query the repository with the SymbolDescriptor to get the actual definition.

@emidoots
Copy link
Member

Got it, that makes sense. So it was talking about the TS/JS cross-repo j2d. Thanks for the clarification @felixfbecker !

@felixfbecker
Copy link
Author

Who's gonna implement this for the Go LS?

@rothfels
Copy link

@felixfbecker I think @slimsag should implement this on the Go side, see my note in slack.

@felixfbecker felixfbecker requested a review from beyang January 16, 2017 15:51
@emidoots
Copy link
Member

Yes, I will implement for the Go LS

@emidoots emidoots closed this Jan 16, 2017
@emidoots emidoots reopened this Jan 16, 2017
@rothfels
Copy link

@beyang please provide final LGTM

@felixfbecker felixfbecker merged commit 2a4279b into master Jan 17, 2017
@felixfbecker felixfbecker deleted the workspace-symbols-extension branch January 17, 2017 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants