how to switch/control syntax highlighting in eclipse flexibly? - eclipse

I have a file with extension .xml.
But it doesn't necessarily contain XML. It may also contain HTML and JavaScript. Now I would like to either have Eclipse decide inteligently/heuristically which syntax highlighting would be appropriate or to switch it myself.
Any ideas?

Eclipse associates files with an editor. You can let eclipse decide which editor to use (e.g. defaults per file extension) or select the editor by yourself. I guess you might already know that or have at least experienced it.
Syntax highlighting isn't always set seperately but instead part of some editor (together with stuff like keyboard shortcuts). So what you are going to need is an editor that behaves the way you want it to. I do not know if there is an editor like this available but one options is writing an eclipse plug-in and implementing such an editor.
Fortunately there are great editors for each of XML, javascript, HTML, etc that are all open source. I guess you might be able to use some of their code. Ideally as a client of their API / Objects or if it won't work out just by reusing code.

short answer: not possible. use PHPStorm instead :)

Related

WebStorm formatting settings - port to another editor

Is there any way to get another editor, like VSCode, to format code ( JavaScript in my case, if it matters ) like the WebStorm IDE formats code by default? I'm not familiar with that IDE, but I'm hoping that it uses a config of some sort that can maybe be exported and imported in another editor. I tried looking for one, but couldn't find anything.
The core problem, if it matters, is that all of our team members use WS to write code and they use the built in formatter, so if I use another one it creates inconsistencies and long commits when editing already written files. As you are probably guessing by now, I would like to use another editor, because I find IDE's bloated and slow.
I don't know if there is a way to import Webstorm formatting rules into VS Code, but I think there is another solution:
I remember in one of the projects i worked on, we used a linter which also auto-formatted code. The advantage is that Webstorm and VSCode can pick pick the linter rules automatically, and then you have same formatting on both.
The downside is that you would need to agree with the team on what does rule will be and then configure them on the linter.

Is there a way to create templates for text files in Eclipse?

In Eclipse, I really enjoy being able to create templates for things I commonly write in Java and XML. While there is some room for improvement, templates have proven to be quite the time saver. Today I was documenting some notes in the release notes. We have a specific format that we write said release notes in. I thought it would be handy to write a small template so that I could easily insert most of the boiler plate text when I amend the notes. So I dug around the eclipse settings and didn't see anything for plain text files. I googled around and also didn't see anything.
So is what I'm wanting to do possible in Eclipse? Is there a plugin I would need to enable such a feature?
I assume the closest you can get is using Snippets
Add the view by clicking Window -> Show View -> Snippets. In that view, right-click and select Customizeto create custom snippets. You can now add those snippets in your textfile by double-clicking them.
Maybe there is also some shortcut feature I didn't find yet...

How to Add Legal Syntax to Language in Eclipse

I've seen similar questions to this on StackOverflow regarding adding highlighting to a language, but what I'm concerned with is getting Eclipse (I'm guessing xtext?) to stop marking certain syntax as incorrect for a language.
Specifically, I have a wrapper from which I call PIG files that looks for certain syntax in the PIG file that would normally be illegal in PIG and substitutes a template for it. I'd like Eclipse to stop marking this syntax as incorrect and giving me ugly red x's in my folder structure because of it. Is there a simple way to do this? Or failing that, to at least disable marking of incorrect for that language in general?
Generally, error markers are created by two entities: editors and builders (compilers). If your existing editor understands the PIG format, it might display parse errors in the opened editor as you are typing. The only way to disable this feature is to re-open the file using a different editor (right-click the file, select Open with... and find an editor - e.g. plain text editor). To support syntax highlighting/error display in other parts, but not in special parts, you have to provide your own editor - that can be written using Xtext.
If the error markers are provided using a builder, then they are only refreshed on save - when it tries to understand the format, and provide an output. In this case, you only have to make sure that the templates are substituted before the file is executed (you can reorder the builder in the project preferences if needed). If you have no such builder, you could disable the PIG builder, that would prevent displaying the erroneous markers (however, it also disables displaying the correct ones as well).

How does Eclipse do code completion specific to third-party frameworks?

How does the Eclipse editor work to enable code completion? For example, within the XML editor for Hibernate property files, if I ctrl-space within a tag, a list of possible value relevant to hibernate will show up.
I understand that the XML editor is pre-configured to understand xml tag, but how about tag specific to a particular framework? How does Eclipse know about that?
I believe that the eclipse XML editor gets the content assist information from any referenced DTDs, or XMLSchema information it associates with the XML file. Try this experiment: Remove the DOCTYPE entry at the beginning of the file and see if content assist still works.
If you're interested in writing your own content assistants, you may want to start by reading the following:
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/editors_contentassist.htm
In a nutshell, like most things in Eclipse, this is a platform hook. When you press the button, it queries all the registered assistants (I'm simplifying here), and they provide suggestions based on the current element or even the current content.
When writing a source editor or viewer for a particular language or document type, it is common to provide at least some rudimentary content assistants.
Removed the DOCTYPE entry at the beginning of the file and im now able to see the commands while typing ctrl+space...
To add to Uri's answer, you can define your own editor for your own language with XText as long as you have a simple EBNF grammar language for your DSL (domain specific language).
You will have:
syntax coloring,
model navigation (F3, etc.),
code completion,
outline view, and
code templates.
Here is a solution you can work. Actually I was facing a same problem with struts.xml file. I was not able to produce tags by cntrl+space
what i did was...
go to Preferences...Java...Editor...Content Assist...Advanced
check all the check-boxes ON and press OK.
sometimes the problem persists due to some false alarming in eclipse. If it happens, just delete your xml file and create a new one in same location.
I hope it will help.
I had the same issue while using the struts.xml file.
I got fix when I tried below...
Go to “Preferences>Java>Editor>Content Assist>Advanced“. Make sure “Java Non Types Proposals” are ticked on both the places as shown in the image below then click Apply and OK button:-

Lightweight editor for web.config files

I'm looking for a lightweight text editor for web.config files which has colour syntax highlighting (like in visual studio).
Any suggestions?
You can use Notepad++. When you work with web.config select XML language to get color syntax highlighting. It looks like this.
Well obviously you can use any editor (e.g. EditPlus or Notepad++) but if you're looking for a light weight editor client that "knows" what a web.config is have a look at ASPhere
http://blogs.msdn.com/publicsector/archive/2007/12/07/free-utility-web-config-editor-with-a-great-ui.aspx
I use ASPhere. It's great!
About ASPhere ...
ASPhere is a freeware utility
primarily intended for creating and
modifying configuration files for
ASP.NET. But they are not only
web.config files ASPhere can work
with, you can use it for viewing and
editing normal XML files and plain
text files as well.
http://www.asphere.cz/en/index.html
I use Notepad2 for that and many other editing purposes. Freeware, totally usable, quick and light - all you can ask for. Highly recommended.
Marc
in the notepad++
Settings -> Style Configuration -> in the left Listbox select XML -> at bottom the "User ext.:" textbox set "config".
Done
The Scintilla SciTE is ultra lightweight, and does XML syntax coloring.
SciTE is a SCIntilla based Text Editor. Originally built to demonstrate Scintilla, it has grown to be a generally useful editor with facilities for building and running programs.
The download page says:
A single file executable called Sc1 (530K) does not need any DLL or properties files as these are linked into the executable.