Community
Participate
Working Groups
Build Identifier: 20110218-0911 Both when formatting (CTRL+SHIFT+F, of right mouse click action) a whole source file, or when selecting lines and trying to format, nothing seems to happen, certainly the format specifications ar not honored. Example. I have in my source a number of places where there is no space in an assigment before or the assignment operator. Like this: needEscape=true; Formatting preview (detail) shows this: var index = 0; In my preferences (named MijnFormatterVoorkeuren, dutch for My Formatting Preferences) I have specified to have a space before and after assignment operators. Preview on tab whitespace, then expressions node, then assignment node: var arr = new Array(); var a = -4 + -9; var b = a++ / --a; a += 4; var value = true && false; Reproducible: Always Steps to Reproduce: 1. Check formatting options. 2. Press CTRL+SHIFT+F 3. Nothing happens....
Are you working with a file in a source folder of a JavaScript Project?
I do not exactly know I I can answer your question correctly. The project is a web-project. The contents of the .project files are as follows: <?xml version="1.0" encoding="UTF-8"?> <projectDescription> <name>fakt400-html</name> <comment></comment> <projects> </projects> <buildSpec> <buildCommand> <name>org.eclipse.wst.common.project.facet.core.builder</name> <arguments> </arguments> </buildCommand> <buildCommand> <name>org.eclipse.wst.validation.validationbuilder</name> <arguments> </arguments> </buildCommand> </buildSpec> <natures> <nature>org.eclipse.wst.common.project.facet.core.nature</nature> <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> <nature>org.eclipse.wst.jsdt.core.jsNature</nature> <nature>org.python.pydev.pythonNature</nature> </natures> </projectDescription> (The pydev nature is there for some build scripts) Further more the javascript files are contained in a subdirectory of the WebContent directory.
Can you also post the contents of the .settings/.jsdtscope file?
Sorry for the delay, I was away for a few days. Here are the contents of the requested file: <?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="WebContent/javascript"/> <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject"> <attributes> <attribute name="hide" value="true"/> </attributes> </classpathentry> <classpathentry exported="true" kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/> <classpathentry exported="true" kind="con" path="org.eclipse.wst.jsdt.USER_LIBRARY/jquery"/> <classpathentry kind="con" path="org.eclipse.wst.jsdt.USER_LIBRARY/fakt400-html"/> <classpathentry kind="output" path=""/> </classpath>
And where was the file in this project?
Hello, My file was actually in a subfolder WebContent/fakt400gui. However the same problem occurs in WebContent/javascript. After some further testing I suspect that the problem has to do with either the size of the file, or the number of changes. I took a large javascript file (lispanel.js - I will attach it to this bug). Formatting would NOT work. When I truncated the file to a bit more than 200 lines, formatting would work. To test wether the size of the file was the problem, or the number of changes, I first formatted the first 200 lines. Formatted them. Then another 114 lines (to prevent cutting a function in the middle). These formatted OK. Then another 150 or so. Formatting did not work. Cut the source to 405 lines. Formatting worked. Added the lines just cut back in. Formatting still did not work. Now copied already formatted source in place of lines just re-added. So all source formatted. Then added one unformatted line. Formatting worked. Now started adding functions one by one and formatting. At a certain moment formatting stopped. Removed the last unformatted function. Added some dummy lines and one unformatted line. At about 400 lines, formatting no longer worked. My conclusion: formatting stops working at a certain size of the source.
Created attachment 208086 [details] Source that will not format, because (I think) it is to large.
character '/' make problem.
(In reply to Tsogtgerel Tsogtsaikhan from comment #8) > character '/' make problem. Hi, Tsogtgerel! Could you please tell us which version of JSDT are you using?
I use just Neon.2 Release of the Eclipse Java EE Developers package. I think it's bug for eclipse generally not only for JSDT.
I’m having similar issues with Ronald. In my case (and, I suspect, Ronald’s) it’s not caused by file size. I believe the formater cannot correctly parse some kinds JS syntax, and if it encounters them it refuses to format the file. Since there’s no indication which syntax it doesn’t like, it’s tricky to notice. I started with one of the file it doesn’t work, and by removing stuff I reduced it to this nearly-minimal test case: ------------------- function test(){ var y = (1, 2); } ------------------- I can add spaces anywhere in the example above, and Format does nothing to fix it. In this case, it seems to be the comma operator that it doesn’t like, but I think I’ve encountered other cases in the past. (Strangely enough, my version of Eclipse *does* format the example attached by Ronald. I think it’s because there are different parsing bugs between our versions of Eclipse. It also routinely format much larger files, as long as they don’t contain syntax it doesn’t like.) Eclipse version info: Eclipse IDE for Java Developers Version: Neon.2 Release (4.6.2) Build id: 20161208-0600 JavaScript Development Tools Version: 2.0.0.v201608301904 Build id: @build@ (<-this is probably a bug) (I’m actually using an Eclipse Platform release binary with manually installed JDT and WTP.)
Yes it is do to new node syntax. This neon.1 I had a very small file. Will format: x(function(z) { ...some stuff ...}); Will not format: x((z) => { ...some stuff...}); It also doesn't seem to matter whether you are selecting just a portion of the file or the whole file. If anywhere in the file there is syntax like above, even though not in the section being formatted it will not format. This is very annoying.
Hi, This also happens for the following snippet (Version: Neon.2 Release (4.6.2)): for (let listItem of listItems) { }
I hit the same issue and found this bug, I also assumed it was down to size but confused since other files would parse fine. As suggested by others I removed pieces of code until I narrowed the parsing error down to a single line: function( char ) { return map[ char ]; } It baffled the hell out of me but turns out the variable name "char" crashes the formatter, renaming it to "character" and the whole file formatting now works fine. This may not be the only "type" variable name that breaks the formatter, didn't bother to check all. Version: Neon.3 Release (4.6.3) Build id: 20170314-1500
I'm also having this issue with Neon.2, latest (as of this comment) JSDT from the release repository installed. When I try to format code that contains a "class" key name, the formatter does nothing.
I've found that any JS file that includes a <Promise>.then().finally() will fail to format. If you comment out the .finally() block it formats; put it back, and it fails.
(In reply to Floyd Elliot from comment #17) > I've found that any JS file that includes a <Promise>.then().finally() will > fail to format. If you comment out the .finally() block it formats; put it > back, and it fails. Actually, to be more precise: you don't need the .then(). It will fail with just <Promise>.finally() as well.
Well, I think I've figured out the use-case when this problem occurs: it's whenever you use a method that's also a JavaScript keyword, so, as noted above "finally" in <Promise>.finally() kills the formatting, as does "continue" in cursor.continue() when using the IndexedDB API.
Oxygen.1: It appears that the problem occurs when a reserved word appears as a key: var func = shape.function breaks alt-ctrl-f, var func = shape["function"] does not. Reading the other comments, this also appears to be the case when keywords are encountered in unexpected circumstances, e.g. <Promise>.finally(). Perhaps the solution is to do keyword validation after formatting. The change above worked when I copied the existing code to a new file (ctrl-c / ctrl-v on the file contents) and edited it before saving it. The original file and a file copied using ctrl-c / ctrl_v on the file itself in eclipse still did not format. F5, project clean, and restart did not help. Neither did restarting eclipse with -clean specified.
Version: Neon.3 Release (4.6.3) Build id: 20170314-1500 JavaScript Development Tools Version: 2.0.200.v201612211424 This also appears to be a problem when dividing inside parenthesis then again outside. For example the following will not format: function test() { var y=(1 / 1) / 1; }
It seems that various ES2015 features break formatter. When I add this code, formatter no longer works. const f = { ...obj, a : 1, b : 4 }; JSDT 2.1.0.v201706011953
Using JSDT 2.1.1.v201803202007 (in Oxygen), statements like these also prevent the formatter to work at all, even on small files: import { Something, SomethingElse } from 'test.js'; or: for (let x of y) { doSomething(); }
Version: Neon.3 Release (4.6.3) Build id: 20170314-1500