How to add a system variable to the VariableResolver?

Questions on using RSyntaxTextArea should go here.

Moderator: robert

How to add a system variable to the VariableResolver?

Postby 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?

Posts: 1
Joined: Tue Oct 29, 2013 11:09 am

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

Postby 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).


User avatar
Posts: 852
Joined: Sat May 10, 2008 5:16 pm

Return to Help

Who is online

Users browsing this forum: No registered users and 1 guest