Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 364618 - [Content Assist]: lookupCrossReference not working in empty documents
Summary: [Content Assist]: lookupCrossReference not working in empty documents
Status: CLOSED WORKSFORME
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.0.0   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-23 11:30 EST by Reiner Hille CLA
Modified: 2017-09-19 17:25 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Reiner Hille CLA 2011-11-23 11:30:34 EST
Repro:
-Create emptry project with following grammar:
==================================
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Script:
	(statements+=Statement)*;
	
Statement:
	(VariableDeclaration|VariableReference) ';'
;

VariableReference:
	var = [VariableDeclaration]
;


VariableDeclaration:
	"var" name=ID;
====================================
- Generate, run Target platform, create project.
- Create "file1.mydsl" with content 
==========
var v1;
==========
- Create "file2.mydsl" (empty).
- Press Ctrl-Space. The only proposal is "var".
- Type "v1;" -> File is valid
- Press Ctrl-Space again. Now proposal "v1" appears (beside "var").

Reason: 

Problem is that AbstractMyDslProposalProvider.completeVariableReference_Var() doesn't create proposals as long as the file is logically empty. At this point in time the root object "Script" has not yet been created. Therefore the parameter "model" is null. Therefore ReferenceProposalCreator.lookupCrossReference will not ask the (global) scope provider for possible references.

I would suggest to find a way that the root object of a grammar is initialized earlier and ideally is never null.
Comment 1 Sebastian Zarnekow CLA 2011-11-25 11:25:35 EST
This behavior is expected if your root rule refuses to instantiate an element because everything is optional.

Please try 

Script:
    {Script} (statements+=Statement)*;

to force the parser to instantiate a model. Please reopen if the problem persists.
Comment 2 Karsten Thoms CLA 2017-09-19 17:13:52 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 3 Karsten Thoms CLA 2017-09-19 17:25:34 EDT
Closing all bugs that were set to RESOLVED before Neon.0