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

Symbols Support #265

Merged
merged 5 commits into from
Sep 1, 2020
Merged

Symbols Support #265

merged 5 commits into from
Sep 1, 2020

Conversation

appilon
Copy link
Contributor

@appilon appilon commented Aug 27, 2020

This provides initial support for symbols navigation. Only supports symbols within the active file, and only jumps to provider, resource, and datasource blocks.

Closes #263

@appilon
Copy link
Contributor Author

appilon commented Aug 31, 2020

Just FYI there was some flakyness with the tests, they failed, and then passed after being re-run (windows in particular)

@radeksimko
Copy link
Member

Just FYI there was some flakyness with the tests, they failed, and then passed after being re-run (windows in particular)

Aye, I assume that's related to #206 I'm not sure why it usually appears on Windows, but my theory is that it may be just slower to execute in that environment and therefore more likely to hit that race condition.

Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

Given the current limitations of the parser this LGTM and I'd be happy to merge it, but it also means that we should prioritize resolving #8 if we keep the waiting logic in.

cfgBlock, err := p.ParseBlockFromTokens(block)
if err != nil {
p.logger.Printf("parsing config block failed: %s", err)
continue
Copy link
Member

Choose a reason for hiding this comment

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

Just curious what's the motivation here behind logging and not erroring out here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not want a file with blocks we don't support yet var, local, etc to return an error to the client, I rather just log and move on

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha, that makes sense - can you just document this reasoning in the form of an in-line comment above the log line?

func (r *datasourceBlock) Type() string {
return r.Labels()[0].Value
func (d *datasourceBlock) Type() string {
return d.Labels()[0].Value
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for fixing this! 👍


// TODO: block until it's available <-pf.ParserLoadingDone()
// requires https://github.com/hashicorp/terraform-ls/issues/8
// TODO: replace crude wait/timeout loop
Copy link
Member

Choose a reason for hiding this comment

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

🤔 I first thought this is "dirty", but then I realized that it may represent just the right balance between waiting for too long or erroring prematurely. So with that in mind I don't think it's crude, I actually think that functionally this is a sensible and pragmatic solution we could replicate in other handlers too eventually.

The only things I'd be careful about is

(a) the timeout - 3 seconds feels quite long to me, I'd reduce it down to 2 seconds max

(b) how this positions us towards/against complying with LSP. As far as I understand this waiting mechanism greatly increases the chance of us providing outdated data, and so that may put more pressure on resolving #8 otherwise we're diverging from the LSP, which we shouldn't be. This is why I leaned more towards erroring than waiting in the completion handler.

Copy link
Contributor Author

@appilon appilon Sep 1, 2020

Choose a reason for hiding this comment

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

I can adjust this to max 2s. The reason this is needed is because the documentSymbol request happens right away once a file is opened/changed, in my local testing the parser was never ready right away and it errored everytime. I have never hit a max timeout either fwiw, I suspect the parser just needed a few hundred milliseconds.

Copy link
Member

Choose a reason for hiding this comment

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

The reason this is needed is because the documentSymbol request happens right away once a file is opened

I see, I wasn't aware of that. In that case I assume it's actually desirable to even wait longer before responding? i.e. we can and should tolerate longer timeout.

I was just applying caution because I saw some clients setting hard timeout for responses for some methods - e.g. formatting in particular is expected to be done within a second or two in some clients's implementations, otherwise the request is just cancelled. I assume the caution is not applicable to all methods then.

So feel free to keep it at 3 seconds.

Copy link
Member

Choose a reason for hiding this comment

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

Regardless though we really need to resolve #8

@radeksimko radeksimko self-requested a review September 1, 2020 16:06
@appilon appilon merged commit a2cdcae into master Sep 1, 2020
@appilon appilon deleted the symbols branch September 1, 2020 18:04
@ghost
Copy link

ghost commented Oct 9, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the context necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators Oct 9, 2020
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.

Add support for symbol navigation
2 participants