How to add a system variable to the VariableResolver?

Post a reply

:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Topic review

Expand view Topic review: How to add a system variable to the VariableResolver?

Re: How to add a system variable to the VariableResolver?

Post by robert » Tue Nov 12, 2013 2:17 pm

Hi Christian,

Sorry for the late reply. You might consider opening a ticket on GitHub asking about this, as the author of the JS language support will get notification of it and might reply (I don't think he monitors this forum).



How to add a system variable to the VariableResolver?

Post by cschulze » Tue Oct 29, 2013 12:28 pm

I'm using Rhino to script my application in JavaScript and want to provide a code editor to the users.
When executing the scripts I'm going to pre-define certain "global variables" which can be used to script my application.
In order to provide meaningful code completion I want these variables to show up in the code completion tab as if they were defined in the parsed source files.

I tried the following to add a "system variable" to the VariableResolver but unfotunately the variable doesn't show up during auto completion.

java code:

JavaScriptLanguageSupport jsSupport = new JavaScriptLanguageSupport()
protected JavaScriptCompletionProvider createJavaScriptCompletionProvider()
provider = new SourceCompletionProvider( isXmlAvailable() );
completionProvider = new JavaScriptCompletionProvider( provider, getJarManager(), this );
return completionProvider;

VariableResolver resolver = provider.getVariableResolver();

CodeBlock block = new CodeBlock( 0 );
JavaScriptVariableDeclaration declaration = new JavaScriptVariableDeclaration( "myApp", 0, provider, block );
block.addVariable( declaration );
declaration.setTypeDeclaration( JavaScriptHelper.createNewTypeDeclaration( "myPkg.SomeClass" ) );
resolver.addSystemVariable( declaration );

I've then tried to add the completion proposal manually by doing the following:

java code:

VariableCompletion completion = new VariableCompletion( provider, "myApp", "myPkg.SomeClass" );
provider.addCompletion( completion );

But this didn't help either.

Can anybody please explain to me how I can achieve my goal?