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

Returning empty array for onReferences() throws a TypeError #92072

Closed
sgranade opened this issue Jan 25, 2020 · 18 comments
Closed

Returning empty array for onReferences() throws a TypeError #92072

sgranade opened this issue Jan 25, 2020 · 18 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug references-viewlet verified Verification succeeded
Milestone

Comments

@sgranade
Copy link

In my language server implementation, if I return an empty Locations array, null, or undefined from a call to onReferences(), then a TypeError is raised.

let connection = createConnection(ProposedFeatures.all);
connection.onInitialize((params: InitializeParams) => {
	return {
		capabilities: {
			referencesProvider: true
		}
	};
});
connection.onReferences(
	(referencesParams: ReferenceParams): Location[] => {
		return [];
	}
)

This results in the following:

rejected promise not handled within 1 second: TypeError: Cannot read property 'items' of undefined
extensionHostProcess.js:820
stack trace: TypeError: Cannot read property 'items' of undefined
	at g (c:\Users\steph\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\ms-vscode.references-view\dist\extension.js:1:8246)

Is this an issue with the language server implementation or a VS Code issue?

Setup:

  • vscode-languageserver 5.2.1
  • vscode-languageserver-protocol 3.14.1
  • VS Code 1.41.1
  • OS: Windows 10.0.18362.
@rcjsuen
Copy link
Contributor

rcjsuen commented Jan 25, 2020

@sgranade Doesn't sound like a bug with your language server to me.

What do you see in your VS Code's "References" view? Do you at least get a No results found. message similar to what you'd get if you tried to search for the references of some word in a comment for example?

@sgranade
Copy link
Author

Yeah, I get a "No results found." message like I should.

@dbaeumer
Copy link
Member

To me neither. I check the LSP code and a empty [] is converted into an empty []. Even undefined and null are allowed per API spec.

Moving to https://github.com/microsoft/vscode-references-view

@dbaeumer
Copy link
Member

@jrieken I cannot move to the issue to https://github.com/microsoft/vscode-references-view.

Any idea what could cause the exception in the references view code. I did a quick check of the code but couldn't detect a code path that would cause this.

@jrieken
Copy link
Member

jrieken commented Jan 27, 2020

🤷‍♂ idk - the viewlet should be able to handle the empty case, e.g that's what you get when search for references on a keyword or string. Are those steps above all it takes to reproduce? Can someone create a repo with just vscode.d.ts API being used?

@dbaeumer
Copy link
Member

I tried this in my testbed and both returning [] and null from the language server works as expected. @sgranade any additional info. Best would be a test case to reproduce.

@sgranade
Copy link
Author

I swear it (didn't) work earlier on the minimum version I posted. Let me go back to my full extension and trim back until I confirm.

@dbaeumer
Copy link
Member

dbaeumer commented Feb 3, 2020

OK, let me know as soon as you have found out something.

@sgranade
Copy link
Author

I've put together a test repo that reproduces the issue. You'll need to compile the extension, debug it, open a .txt file, place the cursor in the middle of a word, and press Alt+Shift+F12.

@dbaeumer
Copy link
Member

I can reproduce this:

capture

@jrieken OK to move to VS Code or is there a special repository for the references view?

@dbaeumer
Copy link
Member

@sgranade thanks for the repro case!

@dbaeumer
Copy link
Member

@jrieken I checked an the LSP clients returns an empty array as well in this case.

@vscodebot vscodebot bot closed this as completed Feb 25, 2020
@vscodebot
Copy link

vscodebot bot commented Feb 25, 2020

This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.

Happy Coding!

@kjeremy
Copy link

kjeremy commented Feb 25, 2020

@dbaeumer I think this was closed in error.

@jrieken jrieken reopened this Feb 25, 2020
@dbaeumer
Copy link
Member

dbaeumer commented Mar 4, 2020

@jrieken
Copy link
Member

jrieken commented Mar 4, 2020

references viewlet issues are in the "main" repo

@dbaeumer
Copy link
Member

dbaeumer commented Mar 5, 2020

@jrieken. Thanks. Moving.

@dbaeumer dbaeumer transferred this issue from microsoft/vscode-languageserver-node Mar 5, 2020
@jrieken jrieken added references-viewlet bug Issue identified by VS Code Team member as probable bug labels Mar 5, 2020
@jrieken jrieken added this to the March 2020 milestone Mar 5, 2020
@jrieken
Copy link
Member

jrieken commented Mar 5, 2020

Thanks for the good repo.

jrieken added a commit that referenced this issue Mar 5, 2020
@chrmarti chrmarti added the verified Verification succeeded label Apr 3, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Apr 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug references-viewlet verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

6 participants