gwtproject / gwt

GWT Open Source Project
http://www.gwtproject.org
1.51k stars 372 forks source link

GWT sourcemaps should map JavaScript function names to Java method names #8460

Open dankurka opened 9 years ago

dankurka commented 9 years ago

Originally reported on Google Code with ID 8477

IntelliJ IDEA supports name mappings (Variables view is still not supported), but GWT
sourcemap doesn't have names.
See screenshot — method named "run" in the source code.

Issue relates to https://code.google.com/p/google-web-toolkit/issues/detail?id=7460

Reported by develar on 2013-12-04 09:30:53


dankurka commented 9 years ago
Sourcemap output is being improved as part as the SoyC reports revamp.

Review here https://gwt-review.googlesource.com/#/c/5502/

Reported by rluble@google.com on 2013-12-04 19:05:49

dankurka commented 9 years ago
This issue is still actual and important for IntelliJ Platform users. 

Since GWT 2.7 (I guess) the situation is much worse — local variables names are mangled
(https://youtrack.jetbrains.com/issue/IDEA-133402 -> https://youtrack.jetbrains.com/issue/IDEA-135094)
— you cannot fix it, sourcemap spec doesn't cover variable name mapping.

But please fix function name mappings. Coffescript/Typescript/Kotlin support function
name mappings.

Reported by develar on 2015-01-13 19:05:03

dankurka commented 9 years ago
Function name mappings and function parameter name mapping (due to https://code.google.com/p/google-web-toolkit/issues/detail?id=9103#c1)
is not supported for GWT, it is easy to fix on GWT side, but not on IDEA side.

Reported by develar on 2015-01-17 15:34:21

dankurka commented 9 years ago
Here is an update:

The soyc report work was completed and available under an experimental compile flag:
-XenableJsonSoyc 

You could try compiling with that flag and see if the sourcemap names field is useful.
However, I think this will increase compile time and sourcemap size too much, so it
shouldn't be the default.

An alternative is to use the -XmethodNameDisplayMode compiler flag which is new in
GWT 2.7. This sets the displayName property on each JavaScript function. See [1]. This
isn't on by default either since it increases JavaScript output size.

We could also change SourceMapRecorder so that it includes name mappings, but only
from JavaScript function definitions to the corresponding Java method name. Perhaps
this wouldn't increase sourcemap size too much. (Currently SourceMapRecorder has a
wantJavaNames parameter but it is all or nothing.)

===

Regarding local variable names, perhaps a quick fix would be to view and watch variables
using JavaScript expressions for now? That's what we do in Chrome and it works reasonably
well. For example, when typing the name of a variable, the prefix is the same as Java
and it will autocomplete the suffix. In the end, it would be nice if IDEA were both
a good Java debugger and a good JavaScript debugger, since GWT programs are both Java
and JavaScript.

I'm working on a different part of the problem right now. See [2].

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/displayName

[2] https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/edit

Reported by skybrian@google.com on 2015-01-21 00:28:58

dankurka commented 9 years ago
>>  perhaps a quick fix would be to view and watch variables using JavaScript expressions
for now?
Our current solution for uglified (uglifyjs) CoffeScript — 

1) we visit source code PSI and find local variables (and other interesting tokens).

2) we map found source tokens to generated. 
GWT produces poor mapping — like "var button = full expression". Ok, we just parse
full line text and find variable name. Only in case of GWT — uglifyjs sourcemap is
correct. But in case of "function parameters" we cannot correctly parse full line text
(we can, but it is a lot of work) and it is the reason why we ask you to produce correct
sourcemap (https://code.google.com/p/google-web-toolkit/issues/detail?id=9103#c1)

Thanks for update. I will try to use experimental flags.

Reported by develar on 2015-01-21 09:02:10

develar commented 9 years ago

GWT debugging improved in IDEA 15:

1) raw name to source (required for call frame view, variables view, inline debugger and auto expressions):

IDEA 15 will strip postfix _\d+_g$ to perform raw name to source name transformation. (According to https://code.google.com/p/google-web-toolkit/issues/detail?id=9106). I don't like GWT way — debugger implementation depends on compiler implementation and it is not reliable (because if you change something on your side, debugger should be updated as well).

Our first approach (describe above, see comment https://code.google.com/p/google-web-toolkit/issues/detail?id=8477#c5) works, but not in all cases. New approach is more reliable, but specific for GWT (it is ok, because only GWT produces incorrect sourcemaps).

2) source name to raw (required for evaluate): partially implemented.

How I can specify flag "-XenableJsonSoyc"? I get error: "Unknown argument: -XenableJsonSoyc Google Web Toolkit 2.7.0"