Project
IntelliJ IDEA
Priority
Normal
Type
Feature
Fix versions
No Fix versions
State
Fixed
Assignee
Maxim Mossienko
Subsystem
No subsystem
Affected versions
No Affected versions
Fixed in build
108.65  
  • Created by   charles eubanks
    7 years ago (11 Feb 2005 08:17)
  • Updated by   root
    2 years ago (17 Jan 2010 20:18)
  • Jira: IDEADEV-3429
    (history, comments)
 
IDEA-27766 javascript "includes"
4
Issue is visible to: All Users
  The issue is visible to the selected user group only
Because of the nature of javascript running in a webbrowser it would be really coooool if you could allow the developer to set an arbitrary set of defined symbols and included code. This way he can, for example, tweek the symbols that javascript editor understands if he knows the script will run in a certain environment – like say IE (document.all blah). This way he can at least see if my file is "green" before throwing it over the transom and into IE.
Of course this won't eliminate errors, and in javascript coding but it can certainly help. And yes it requires some effort on the developer's side to really use the feature.
However if IDEA's javascript editor shipped with the "built in" defined symbols in a file like this it would give the poor developer a place to start tweeking without having to start from scratch.
I realize this notion is half-baked but I hope you can see where I am going with this.

Issue was resolved
Comments (6)
 
History
 
Linked Issues (?)
 
Maxim Shafirov
  Maxim Shafirov
11 Feb 2005 16:21
7 years ago
What about @param -like annotations in the top-of-the-file comment?
charles eubanks
  charles eubanks
11 Feb 2005 21:39
7 years ago
The devil is in the implementation. If you are thinking about implementing something like:

// #DEFINE x = "y"

then I would lobby for

// #INCLUDE x.js

where x.js has content like:

var x = "y"

Going for #INCLUDES vs #DEFINES would allow inclusion of files that are themselves self-contained libraries.
But it would also allow inclusion of emulation files – eg a file that defines either IE or Mozilla specific DOM extensions (and is probably only written so that the editor doesn't complain – never actually touches a web browser)

However, the #DEFINE approach is a start and would be useful in simpler cases.
I deal with some fairly complicated javascript library so I am looking for includes.
And if you implement the #INCLUDE feature the next thing somebody will ask for is a global #INCLUDE that doesn't need a magic comment at the top of the js files....

Anyway, if you work with big enough javascript projects you find that the browser dependencies and library dependencies keep on multiplying as things get bigger. Javascript is so loosely structured that a smart IDE can really make a difference for the poor developer.
Boky
  Boky
15 Mar 2005 11:47
6 years ago
Hello.

My company uses javascript (rhino) on the application server, so I think I can give you some input:

This javascript runs in completely different environment than the client-side javascript. There's no "document.all" or "document" as a matter of fact, but there are some other predefined classes that exist. This are all java classes and are available through the global variables.

For example:
global variable "wizard" maps to com.some.package.Wizard
global variable "log" maps to org.apache.log4j.Logger
...

So, what would be usefull is to set up an environment in the same manner as you set it now for Java files:

1. "Use these and these JARs and these directories for libraries"
2. "Declare implicit variable XXX which is of type com.some.package.XXX"
3. "Declare implicit variable YYY which is of type com.some.package.YYY"

Then, Idea could use "reflection" (in much the same way that rhino does):

class Foo {
void setBar(String s) { ... }
String getBar() { ... }

void setA(String s) { ... }
String getB() { ... }
}

From javascript:
foo.bar = 'a';
var a = foo.bar;

foo.a = 'something';
var a = foo.a; // Error - cannot read write-only property

foo.b = 'something'; // Error - cannot write read-only property
var b = foo.b;


There are plenty of HTML DOM implementations in java already outthere. This way, you would only need to say (for web-side editing):

"Declare implicit 'document' variable to be of class org.some.package.HTMLDocument" - and - voila! - it works!

(Worst case scenario: the DOM model needs to be (re)written.)
Keith Lea
  Keith Lea
05 May 2005 01:40
6 years ago
I think this could be implemented as a module-level setting. Then you could have a base "common javascript" module, and "mozilla-specific js" and "ie-specific js" modules. This is just an idea, and I think it might be overly verbose, because often you want to combine code for all browsers into one module, for convenience (or even in the same file).
Boky
  Boky
09 May 2005 14:09
6 years ago
Module-level setting is defenetly the way to go.

I don't see much of the GUI part yet, but first version should probably be easily implemented with just a simple table:

[Global variable name] [Class browser]

So, you would say something like:
document = org.some.package.with.html.dom.implementation.HTMLDocument
or
document = org.some.package.with.html.dom.implementation.MozillaSpecificHTMLDocument
or
document = org.some.package.with.html.dom.implementation.IESpecificHTMLDocument
or
log = org.apache.log4j.Logger

The interpreter would then work as if it had an instance of this class. How exacly is this instance created, is not important.

Later on you could probably add some "init" include functionality javascripts, that would create some javascript objects and let them be used in the code:

For example, you could have an "init.js" file that looks like this:
var SomeObject = new Object()
SomeObject.print = function() { alert("hello world"); }

After a javascript editor is invoked, this scritp would be executed, and all global objects exposed (I think that rhino at least allows you to inspect which global object exist), so that you could say in the editor something like:

SomeObject.print();


The init script could be ran once, objects inspected, their methods/properties read and cached for the next time :-)
Maxim Mossienko
  Maxim Mossienko
14 Apr 2007 20:09
4 years ago
This is possible long time ago (e.g. in Demetra), just add javascript file with definitions like
document.myproperty = 0;
and -myproperty- will be available for completion/resolve