Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

all: implement workspace/reference v2 #48

Merged
merged 5 commits into from Dec 9, 2016
Merged

Conversation

slimsag
Copy link
Member

@slimsag slimsag commented Dec 6, 2016

According to the new specification at sourcegraph/language-server-protocol#8

Please do not merge until that PR is.

Copy link
Member

@keegancsmith keegancsmith left a comment

Choose a reason for hiding this comment

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

Please do not merge until that PR is.

How easy would it be to update? Assuming we don't get the other PR merged just yet, if its easy to update lets merge in and get some stuff in prod :)

// Non-standard fields.
"dir": defPkg.Dir, // TODO: emit standard "file" instead?
"pkg": defPkg.ImportPath,
"vendor": IsVendorDir(defPkg.Dir),
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't these fields live in meta?

Edit: forgot to remove this comment, later commits fixed this

@@ -217,7 +217,6 @@ func (h *LangHandler) externalRefsFromPkg(ctx context.Context, bctx *build.Conte
ContainerName: defContainerName,
PackageName: defPkg.ImportPath,
Meta: map[string]interface{}{
"dir": defPkg.Dir, // TODO: emit standard "file" instead?
Copy link
Member

Choose a reason for hiding this comment

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

surprised you didn't need to update tests with this commit?

Edit: I see you updated in a later commit

according to the new specification at sourcegraph/language-server-protocol#8

- langserver: remove 'dir' from workspace/reference
  - It's not useful to us, and would have to be translated by the build server into a repo-relative path anyway.
- simplify goRangesToLSPLocations implementation
@slimsag
Copy link
Member Author

slimsag commented Dec 8, 2016

  1. I've updated the workspace/xreference implementation to reflect the latest specification.
  2. I've also added a textDocument/xdefinition implementation according to the spec.
  3. I've also squashed this down into just a single commit for workspace/xreferences and textDocument/xdefinition.

The xreference impl has not changed much since @keegancsmith reviewed it, but the second commit / xdefinition implementation is new so I'll need to get a review on that. @keegancsmith I will ask someone else to review because I want to land this into master today, but please leave comments etc here and I will follow up tomorrow morning.

This is useful for integration tests in the Sourcegraph core codebase.
l.Location.Range.End = l.Location.Range.Start

// Determine metadata information for the node.
//rootFile := pkg.Files[0] // TODO: is this correct?
Copy link
Member

Choose a reason for hiding this comment

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

remove commented-out code

Copy link
Member Author

Choose a reason for hiding this comment

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

(hint: it was not correct :) )


// Determine metadata information for the node.
//rootFile := pkg.Files[0] // TODO: is this correct?
def, err := refs.DefInfo(pkg.Pkg, &pkg.Info, pathEnclosingInterval, node.Pos())
Copy link
Member

Choose a reason for hiding this comment

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

Since def is only used within the following if-else block, a clearer way to write this would be:

if def, err := refs.DefInfo(pkg.Pkg, &pkg.Info, pathEnclosingInterval, node.Pos()); err == nil {

} else 

}

@@ -189,10 +180,6 @@ func (h *LangHandler) externalRefsFromPkg(ctx context.Context, bctx *build.Conte
}()
span.SetTag("pkg", pkg)

pkgInWorkspace := func(path string) bool {
Copy link
Member

Choose a reason for hiding this comment

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

If we now emit references to both internal and external definitions, you should change the name and docstring of this function.

Copy link
Member Author

Choose a reason for hiding this comment

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

(done)

Symbol SymbolDescriptor `json:"symbol"`
}

type SymbolDescriptor struct {
Copy link
Member

Choose a reason for hiding this comment

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

Please add a docstring for this type and each of the fields.

// ReferenceInformation is the array response type for the `workspace/xreferences` extension
//
// See: https://github.com/sourcegraph/language-server-protocol/blob/master/extension-workspace-reference.md
//
type ReferenceInformation struct {
Copy link
Member

Choose a reason for hiding this comment

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

Please add a docstring for each of these fields.

File string `json:"file,omitempty"`
ContainerName string `json:"containerName,omitempty"`
Vendor bool `json:"vendor,omitempty"`
Meta map[string]interface{} `json:"meta,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

If SymbolDescriptor itself is "metadata", having a Meta field inside it seems redundant. What about something like Attributes?

Copy link
Member Author

Choose a reason for hiding this comment

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

That would be a spec change, too. But okay.

- Remove some useless/commented code.
- Write an if-else block in a clearer way.
- Cleanup documentation + wording (external -> workspace)
- Add detailed docstrings for all lspext types/fields.
- Rename `SymbolDescriptor.Meta` to `SymbolDescriptor.Attributes`
…parent` meta fields

This give us less ambiguity.
@slimsag
Copy link
Member Author

slimsag commented Dec 9, 2016

Also see: sourcegraph/sourcegraph#2673

@slimsag slimsag merged commit 526e8a1 into master Dec 9, 2016
@slimsag slimsag deleted the sg/workspace-reference-v2 branch December 9, 2016 01:42
slimsag added a commit that referenced this pull request Dec 9, 2016
- Fix issue with `name` and `attr_parent` being reversed when `attr_parent` is present.
- Remove commented-out code that was missed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants