This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 196429 - Javascript code completion not working in JSP files
Summary: Javascript code completion not working in JSP files
Alias: None
Product: editor
Classification: Unclassified
Component: Parsing & Indexing (show other bugs)
Version: 7.0
Hardware: PC Windows XP
: P2 normal (vote)
Assignee: Tomas Zezula
Depends on:
Reported: 2011-03-08 09:04 UTC by Vladimir Riha
Modified: 2011-09-29 09:56 UTC (History)
5 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:

screenshot (116.74 KB, image/png)
2011-03-08 09:04 UTC, Vladimir Riha
A file to reproduce the issue (713 bytes, application/octet-stream)
2011-03-14 12:32 UTC, Marek Fukala

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Riha 2011-03-08 09:04:42 UTC
Created attachment 106814 [details]

The code completion for javascript is not working inside jsp files, see the attachments. If I set cursor between tags script and invoke code completion, it doesn't offer anything. When I typed first letters of the function called "moje()" and again invoke completion, again nothing is offered. Omitting the attribute type of tag script doesn't change anything.

Product Version: NetBeans IDE Dev (Build 201103080000)
Java: 1.6.0_24; Java HotSpot(TM) Client VM 19.1-b02
System: Windows XP version 5.1 running on x86; Cp1250; cs_CZ (nb)

Happens on Solaris 11 as well
Comment 1 Marek Fukala 2011-03-10 10:12:52 UTC
The completion offers nothing if invoked for the second or next time after the file modification. The first completion invocation after the file modification works well. This is observable in JSP files, works well with .html files.
Comment 2 Marek Fukala 2011-03-10 10:34:20 UTC
Correction: The completion works only during the short interval between modification of the file and parsing it, e.g. works only if the latest parser result is dirty.
Comment 3 Marek Fukala 2011-03-10 14:10:25 UTC
There some of the observations I consider as strange (all tested on a JSP file w/ js and html code inside):

1) SourceCache.refresh() is triggered only by a caret move in the opened editor window. Isn't it weird since no file content has been modified?

2) After a modification of the file the calls to EPs are following:
a) JspEmbeddingPprovider called from SourceCache.refresh()
b) JsEmbeddingProvider (note the prefix is Js, not Jsp!!!) called for the first time from GsfHintsProvider by ParserManager.parse() 
c) JsEmbeddingProvider called for second time from SourceCache.refresh(). 

Since the embeddings have been already refreshed by the first call to the JsEP and the file hasn't been modified meanwhile there isn't (or is????) a reason why create the js embeddings again.

3) If I try following scenario: Type to the javascript section in the file and immediately invoke completion, then it behaves as follows: 
a) First JsEmbeddingProvider.getEmbeddings() called from HtmlCompletionQuery by PM.parse()
b) then JspEmbeddingProvider.getEmbeddings() called from the same place
c) then JspEmbeddingProvider.getEmbeddings() called from SourceCache.refresh()
d) finally JsEmbeddingProvider.getEmbeddings() called from SourceCache.refresh()

The #2 and #3 scenarios causes the resultIterator.getParserResult (caretOffset) at the GsfCompletionProvider:326 to return HtmlParserResult for the case #2 and JsParserResult for the scenario #3. But in both cases the JsParserResult should be returned. That is the reason why the javascript completion doesn't work normally and does work only in the scenario #3.

I must admit I am not an expert on the parsing.api so I'm passing the issue to parsing.api and kindly asking Tomas to take a look at it.
Comment 4 Marek Fukala 2011-03-10 14:13:58 UTC
Some more info:
The snapshots given to the JsEmbeddingProvider are in all the scenarios and cases the same - the whole JSP file content and the resulting JS embedding are also always the same - correct.

There's also a nasty workaround for not creating the JS embedding from HTML virtual source created from JSP content. Look at JsEmbeddingProvider$Factory.create() for more info.
Comment 5 Marek Fukala 2011-03-10 14:15:34 UTC
The current embeddings for JSP files are following AFAIK:

JSP -> JS (the transitional JSP->HTML-JS is disabled by the workaround I mentioned)
Comment 6 Tomas Zezula 2011-03-14 09:22:47 UTC
Marku, how can I reproduce it?
Can you attach the file (project) which causes such a behavior and describe what should I do to reproduce it?
Comment 7 Marek Fukala 2011-03-14 12:32:23 UTC
Created attachment 106979 [details]
A file to reproduce the issue
Comment 8 Marek Fukala 2011-03-14 12:34:17 UTC
To reproduce the issue, just place caret somewhere in a white area in the <script> tag content and then follow the steps from comment #3. Briefly - modify the file (hit a spacebar for example), wait a second or two and invoke cc => nothing. Then modify the file and immediately invoke cc => you'll got the proper javascript results.
Comment 9 Tomas Zezula 2011-03-14 12:39:44 UTC
Thanks, Marku
Comment 10 Tomas Zezula 2011-03-14 12:58:12 UTC
I've looked at it and it doesn't seem as parsing api problem.
It seems rather as JSP ep problem.
I've opened the provided file and called cc as described above.

The HtmlCompletionQuery is trying to get result for offset 411 which is OK in the document (the place where the cursor is placed) but it's not OK in the provided snapshot which comes from the JSP in the snapshot the position points somewhere into body element.
Comment 11 Marek Fukala 2011-03-14 13:29:27 UTC
Just to make it clear: We've clarified the problem mentioned in comment #10 offline and the conclusion is it is not an issue and the code is correct.
Comment 12 Tomas Zezula 2011-03-15 16:22:55 UTC
The problem is in wrong embedding layout in the JSP.
The jsp has following embeddings for the test document

while it should be


The javascript and html both are having the same positions(javascript is contained in html), so the first (which is random) wins.
As Marek explained that the wrong layout is needed and it's impossible to change it I am proposing
a fix to parsing api which will preserve the order of embedding providers. The order will ensure that javascript will win over the html.
Comment 13 Tomas Zezula 2011-03-15 16:24:04 UTC
Fixed jet-main a5396573a821
Comment 14 Marek Fukala 2011-03-15 21:38:20 UTC
Thanks Tome for the fix. Just a few notes: I do not think the current embeddings layout is wrong. There's nothing forbidding such layout generation in the parsing api javadoc. I remember when I discussed the problem with Hanz some time ago and he said it is simply not defined how it should behave :-). Note #2 - I didn't say it is impossible to change the layout, but the way how it's done now has some advantages and redoing this now would be possibly more risky than the ordering fix you did. Thanks for your work and patience once again!
Comment 15 Tomas Zezula 2011-03-16 08:18:37 UTC
>it is simply not defined how it should behave :-)
This is exactly what this bug is about. It's not defined, sometimes the JS wins and CC works sometimes HTML wins and it does not as the both embedding have overlapping range. The resultIt.getResult(offset) does not know which one to choose as both are OK.
I've did a change which orders them according to task priority.
Comment 16 Quality Engineering 2011-03-16 09:42:45 UTC
Integrated into 'main-golden', will be available in build *201103160400* on (upload may still be in progress)
User: Tomas Zezula <>
Log: #196429:Javascript code completion not working in JSP files
Comment 17 Vladimir Riha 2011-03-16 09:46:21 UTC
I'll verify it as soon as the build will be available
Comment 18 Petr Jiricka 2011-03-16 12:43:34 UTC
For now this is fixed in trunk, right? Adding 70_HR_FIX_CANDIDATE.
Comment 19 Vladimir Riha 2011-03-16 13:03:33 UTC
Comment 20 Jan Lahoda 2011-03-16 14:15:33 UTC
The patch seems fine to me.
Comment 21 Tomas Zezula 2011-03-17 14:23:29 UTC
Integrated into NB 7.0
Comment 22 Vladimir Riha 2011-05-20 10:41:51 UTC
I'm afraid I have to reopen this issue. In jsp files in common Java Web - Web Application it works fine, but in Java Web - Web Free form application, the completion doesn't work properly. 

I tried sample project from some TS (project archive is at the bottom) and opened time.jsp.

In time.jsp I simply added js code with function definition and tried to invoke code completion. The completion offers js items (decodeURI(), keywords...) but it doesn't offer anything that I have defined, no functions, no variables... Reopening/saving the file doesn't make any difference.

Product Version: NetBeans IDE 7.0 (Build 201104080000)
Java: 1.6.0_25
System: Windows XP version 5.1 running on x86; Cp1250; cs_CZ (nb)
Comment 23 Tomas Zezula 2011-05-20 12:34:22 UTC
The freeform case has nothing to do with this report.
This issues was about embedding ordering which is general not project specific.
Please create a new issue on the JSP or web/freeform.
Comment 24 Vladimir Riha 2011-09-29 09:56:16 UTC
reverting reopening back to verified...