How to disable error highlighting in VS Code? - java

I need to disable error highlighting in Java files in VS Code. VS Code tries to check a Groovy file while thinking it is a Java file.
As you can see in the picture all imports after the first and the types after the first field are highlighted red (due to missing semicolons). However I do not want the error check for this Groovy file.
NOTE: I only have the plugins Clang, RedHat.Java, Markdown PDF, Sort Lines, and Uncrustify installed. Even if I disable all the red highlighting is visible.

open your preferences file and add this
"java.validate.enable": false
I didn't try it for java, but it works for typescript.

I found this:
"problems.decorations.enabled": false,

You should disable the linter, which is by default enable in VS Code.
To do so you can go to File-> Prefrences -> setting

I wouldn't think this is necessary but you might try:
"files.associations": {
".groovy": "groovy"
}
in your user settings, assuming your file extension is .groovy. If it is something else, just set it to "groovy" as well. When I create a .groovy file with your content or gibberish I get no error linting at all. What is your file extension and what does Vscode call it in the bottom right of the editor? You can click on that file type to change its file associations. See modifying Vscode file extensions.

Related

Is there a way to tell intelij to ignore a file inside a package

I file inside a package and I want intelij to ignore it. every time I ran my code intelij keeps showing me errors and info from that java file. Is there any way for me to make intelij to ignore that file
Right click on the file > Override File Type > Plain Text
Note: This action DOES NOT override the file type of a specific extension. Instead, it override the file type of a specific file
You may switch-off all error highlighting at the top right corner for this file:

How to solve java file mapped to not java file type text

I wanted to add a java class to a project, but I did a mistake and added it as a text file. Then, I removed it and tried to add it again as a java class, but unfortunately it doesn't work anymore. And I get the following error:
Unable to parse template "Class" Error message: ABC.java mapped to not java file type text
As I searched, I faced some solutions like
this one but I can't find File Type under Editor or anything similar that I can change as suggested in the solution.
Any help would be appreciated.
PS: I am using IntelliJ 2018.3.4.
Thanks in advance,
Go on File->Settings and a dialog will open. In that dialog navigate on the left part to Editor/File Types and then you need to choose from the section Recognized File Types Java Class and remove from bottom section the problematic extension (note you have a small minus button on the right)
https://www.jetbrains.com/help/idea/creating-and-registering-file-types.html
This is a variant of Markov's answer that worked in my scenario.
Try going to File->Settings->Editor->File Types and to the Recognized File Types tab. Click the "Auto-detect file type by content" choice, and delete the name of the file you are trying to create from the "File Name Patterns" section by using the minus button.
Select required file type in top list (Recognized File Types) -- do it for "Text files"
In bottom list (Registered Patterns) select undesired pattern -- "SomeFileName.java"
Click on "-" (Minus) button to remove pattern from the list
Repeat 1-2-3 for other undesired patterns
If desired, you can also do this manually by editing config file while IDE is closed. Because it's IDE-wide setting, it is not stored in .idea folder (which has project settinsg only) -- the file to look for is called filetypes.xml and shoudl be located in ~/Library/Preferences/IntelliJIdeaXX/options ( see http://devnet.jetbrains.net/docs/DOC-181 for other OS etc )
Certainly inelegant, but you can simply copy the contents of the file to the clipboard (ctrl-c or similar), delete the file (maybe make a temporary backup somewhere outside the project), then in IntelliJ go to the desired package, right click, select new, select Java Class, name it correctly, and then you can paste in the contents of your file (ctrl-v or similar).

How to disable intellij auto change my code format?

When I edit the java source code, intellij will auto format my code besides the places I edit, how to disable that ?
In the latest IntelliJ Idea (2021.3), Auto formatting can be stopped for one or more file type by going to
Preferences -> Tools -> Actions on save -> Enable or Disable Reformatting action for one or more file type
For those of you who want to disable formatting just for some specific file(s), there is a way since 2018.3 (IDEA-97848).
Go to Settings > Editor > Code Style > Formatter and add your exclusion pattern(s).
I tried disabling trim trailing spaces in code formatting but this doesn't work for my file type '.erb'.
I added my file type '.erb' to selectively disable code inspection for this file type but this doesn't work in IntelliJ version 2016.2.4.
I locked my file after I had made the changes using the lock icon in the Status Bar and this finally worked!
In Preferences > Tools > Actions on save you have a definition
BUT that can be overwritten by the following one, so check in that order:
In Preferences > Editor > Code style > [language] uncheck reformat on file save.
Update: None of those worked for me, so I change my file, commit without save (DON'T save during commit to avoid data loss, you'll be prompted) and then CTRL-Z.
Your file is committed and saved but only with your changes.
FWIW, I'm using Scala, on IntelliJ Community 2021.2, with the Scala plugin.
In my case intellij was messing with all the spaces in the code.
So, I changed following settings :
Editor > General
You can disable IntelliJ IDEA's ability to format (and therefore auto format) specific file types, but it comes at a cost.
To disable :
Settings > Editor > File Types
Select the file type you want to have never formatted
change the extension to something you don't use - for example '*.styl' to '*.oldstyl'
Now, even if you tell IntelliJ to reformat one of these files it won't.
The cost is that you lose syntax highlighting and language support all together.
In my case for stylus files it was worth it.
IDEA kept removing tab characters in sections of code that I wasn't even working in. SUPER annoying and destructive.

Weird compile error in Eclipse and Netbeans

I am getting an error : Syntax error on tokens, delete these tokens, on valid Java code
My code, copied and pasted from eclipse, is here :
public class Test2 {
    public static void main(String[] args) {
    }
}
I am guessing that there is some hidden character in the code which I can't see.
I tried restarting Eclipse, and cleaning the project, but the error is still there!
Even if I copy and paste this code from SO into eclipse the error is still there!
what is going on here?
EDIT
Its not Eclipse! In Netbeans I get the same error :
Also, the original problem occurred when I tried to copy and paste code examples from this webpage http://blue-walrus.com/2011/05/advanced-swing-multithreading-tutorial/
I just did the following:
Cut and paste the code from your Question to a file and compiled it using javac (Java 8). No compilation errors.
Opened Eclipse (Kepler), created a Test2 class, copied the code from the Question to it, and saved it. No compilation errors.
My tentative conclusion is that there is nothing wrong with the java code. (No funky hidden characters, no nasty homoglyphs, no messed up character encodings.) The most likely cause of these weird errors is that your Eclipse session is messed up:
Try restarting Eclipse.
Try closing and opening the Project.
Try loading your code into a fresh workspace.
In extremis ... try a fresh install of Eclipse (same version as before ...)
Following on from my comments your project must have a valid JDK and JRE defined
If these are missing from your project, go to Window > Preferences> Java Installed JREs and click Add..
If you make any changes select Project > Clean... again
To remove these strange hidden empty space characters, I copy and pasted into Outlook Email, and then copy and pasted into Notepad++, and then copied into Eclipse. All fixed :)
Seems you need to copy and paste situations like this through a few different apps, to 'scrub' the text of any funny characters.
I think the java class path is not set in your computer if that is the case go to my computer->properties->Advanced System settings->Advanced tab click Environment variables find variable path & check if the java class path is there. If its not there i suggest you to copy the java class path & edit variable path & paste the url followed by ";" & then restart the eclipse.
better to check your project build path i.e, JRE system library version/is that set or not in the eclipse
way to go for properties section of eclipse :
right click on project - > choose properties ->build path->Libraries->Add Library Variable->JRE system library->click Add alternate JRE radio button->and select your machine jre->click finish->OK
after that go for java compiler in the same window (left side)->check the enable project settings->and choose your java version from drop down box->click Apply->OK
finally save your program and run it
if it again fails you need to check whether you are setting the classpath in proper or not, for this
please refer this link to set classpath :Link
ZWSP and other non-printing characters
Means a Zero-Width-Space character. You are using UTF8 and some characters have a width of 0 so you can not see them.
Change the Encoding to ANSI and back will solve your Problem.

Eclipse autocompletion problem

Just installed Eclipse Helios (Win7 64) and I'm having a strange problem. I type syso-Ctrl-Space which is expected to complete to System.out.println("") but it doesn't work! I searched the web for about an hour now, I set Preferences > Java > Editor > Content Assist to defaults, nothing. Everything else seems to work. Ideas?
To be clear: the shortcut works, it completes everything except "syso" as seen so far, on syso (also tried sysout) it says "No Default Proposals". I couldn't find this kind of shortcuts in the Content Assist, but I set them to default anyway.
If you still cant get auto-completion working,try enabling the Template proposals under Content assist menu.This is the exact location,
Windows->Preferences->Java->Editor->Content Assist->Advanced
And make sure you have only one entry for syso(Under Templates menu).
I believe the right template is "sysout" and I believe this can be configured somewhere but could not tell you where. Try sysout and then Ctrl+Space
It's a template, you can find all templates under
Window -> Preferences -> Java -> Editor -> Templates
There you can see that the template name is "sysout" this will then trigger the string substitution for System.out.writeln() but you can change both the template name (if you prefer syso) and/or the actual code produced by invoking the template
Cheers
I am using Eclipse Galileo and had the same problem. Even after trying the above proposed solutions but it didn't work. After making the below change it finally comes out.
Go to Windows->Preferences->Java->Editor->Templates
Select sysout template and edit it.
Change the context from Java statement to Java.
And it worked for me. I hope this will be helpful for you.
As Peter stated, it is under Window -> Java -> editor -> templates.
Look for the line with the following values.
sysout "Java Statements" "Print to standard out" "on"
the preview should be as follows...
System.out.println(${word_selection}${});${cursor}
Your cursor needs to be located in a place where it would be legal to get that line. If your cursor is within a method definition and you type syso you will get the replacement. However if your cursor is in the portion of the text outside of any method definition, say where you declare variables for your class for instance, then syso will not suggest the illegal line system.output.println();.
I had this problem, read all the answers here, became convinced that it MUST be working in my copy, and realized I had been typing syso BELOW the closing } of my last method instead of in the method.
Eclipse on!
You may try to set the shortcut of Content Assist with ALT+L, if it works, then you can choose your favorite shortcut again. (The shortcut Ctrl+Space conflicts with the shortcut of switching input method). In eclipse on linux, the shortcut of Word Completion is ALT+/, so if you set this as the shortcut of Content Assist it also conflicts.)
Just go to the below address:
Windows->Preferences->Java->Editor->Content Assist->Advanced
and click restore default..........that's all
its work like a charm again.
Also check in this eclipse menu:
Windows -> Preferences -> Java -> Appearance -> Type Filters
If you see java.* or javax.* here then try removing it (or Restore Default will do the job) and see that works, it did for me.
Just found the solution for Eclipse Luna: write syso and press CTRL+Space and click on "enable intelligent code completion" and you are set.
I am sure you can find it somewhere in the options as well but this way it is fast and easy!
DIRTY WORKAROUND:
You can try out the following AutoHotkey-Code if you're still struggling like I am (STILL haven't been able to fix it myself)
#persistent
#ifwinactive ahk_class SWT_Window0 ; eclipse java
:*:syso::
sendraw System.out.println()`;
loop, 2
send {left}
return
#ifwinactive
You need to write this in a .ahk file and run it (AutoHotkey needs to be installed). You might wanna put this file into your startup folder. It's a very useful tool, you might wanna expand it one day.
You might have overlapping shortcuts.. Goto 'Overview' than the 'Keys' subsection. Type "ctrl +space" in the 'filter text' section. You should see the "content assist" and probably another command with the same shortcut. If another shortcut does exists, change its shortcut to something else.

Categories

Resources