Sublime Forum

String gets red in single quote for Sublime Text 4

#1

There is an issue in Sublime Text 4, whenever we put something in single quote complete text gets red, in all earlier versions it is working fine, I have attached the screenshot below from the Sublime 3 and 4 version, where you can see that single quote string and public keywords are marked as Red.

Looking forward to hear from you soon, if I have to change any setting to disable this red color.

0 Likes

#2

What language is it?

Also copyable code snippets would be useful.

0 Likes

#3

@deathaxe - please find the code below to copy paste

public with sharing class VenueTriggerHandler
{
    public static void venueNameChecker(List<Venue__c> venues)
    {
    	Set<String> venueNames = new Set<String>();
    	Set<String> existingNames = new Set<String>();

    	for(Venue__c ven : venues)
    	{
    		venueNames.add(ven.Name);
    	}

    	for(Venue__c ven : [SELECT Name FROM Venue__c WHERE Name IN :venueNames])
    	{
    		existingNames.add(ven.Name.toUpperCase());
    	}
    	if(existingNames.size()==0) return;

    	for(Venue__c ven : venues)
    	{
    		if(existingNames.contains(ven.Name.toUpperCase()))
    		{
    			ven.addError('Name Already Exists!');
    		}
    	}
    }
}
0 Likes

#4

@deathaxe - And the Language is Java, basically I have installed HaoIDE package and using it for Salesforce Development for last 8 years and I am that old guy with sublime journey.

This sublime 4 version updates made text red whichever enclosed in single quote.

I am attaching a full screenshot of sublime screen as well below

0 Likes

#5

ST4’s Java syntax definition strictly follows official language specifications (see: https://docs.oracle.com/javase/specs/jls/se20).

String Literals

According to Chapter 3.10.15 string literals must be enclosed by double quotes.

Single quotes are used to denote character literals (see Chapter 3.10.14), which consist of exactly one character (e.g. 'c') or an escape sequence (e.g.: '\u214').

Java compiler actually throws a compile error on your statement.

debug.java:6: error: unclosed character literal
		ven.addError('Name Already Exists');
		             ^
debug.java:6: error: ';' expected
		ven.addError('Name Already Exists');
		                          ^
debug.java:6: error: unclosed character literal
		ven.addError('Name Already Exists');
		                                 ^
debug.java:6: error: not a statement
		ven.addError('Name Already Exists');
		                           ^

with … class

public with sharing class VenueTriggerHandler

The with sharing expression is also not part of official Java language specs causing java compiler to throw compile error at it

debug.java:2: error: class, interface, enum, or record expected
public with any class VenuTrigger
       ^

As ST4’s Java syntax does not know this construct either it fails highlighting the class definition due to internal implementation details, causing the first public keyword to be highlighted as illegal.

3 Likes

#6

@deathaxe - Sorry for confusion, I meant to say that, this is Salesforce Apex Language which syntax is similar to Java.

public with sharing class - these keywords are only supported by Salesforce Apex.

0 Likes

#7

I am 100% sure that this issue occurred only after updating Sublime from 3 to 4 version, still it is working on Sublime 3 when I uninstalled that Sublime 4.

0 Likes

#8

Java syntax has been completely rewritten to fix reported bugs and to highlight statements/expressions more accurately. It not correctly highlighting foreign syntaxes is not an issue of ST4 or its new Java syntax.

Especially the “with …” clause isn’t highlighted well by ST3 as well.

A possible solution would be to write a dedicated “Apex” syntax definition, which extends ST4’s Java syntax and makes required adjustments to support those “non-java” extensions.

0 Likes

#9

Would you mind to help, how I can setup a dedicated apex syntax to ignore red color for single quotes?

0 Likes

#10

Created an Apex syntax and and published it for download via:

4 Likes

#11

Hi @deathaxe - Thank you so much for creating the Apex package, would you mind to assist me further how I can link it to Sublime text.

I clicked on Brower Packages and paste the download file in the directory but it didn’t work.
I also copied in in the below path
C:\Users\UsmanAliVM\AppData\Roaming\Sublime Text 3\Packages\User

I believe, I am not following the right way.

0 Likes

#12

sublime-package files need to be placed into Installed Packages directory. It’s located next to Packages.

0 Likes

#13

I have added the apex package into installed directory of sublime but it is still showing red text in single quotes.
please find the attached screenshot of packages location and Sublime.

![2|690x484]

0 Likes

#14

Code from Sublime text

0 Likes

#15

Any package located in ST’s install directory (e.g.: C:\Program Files\Sublime Text) is deleted during upgrades. You probably don’t want to place any 3rd-party package there.

Instead follow the instructions from package’s README:

  1. Call Main Menu > Preferences > Browse Packages…
  2. Navigate to parent folder (you’ll find a folder called Installed Packages)
  3. Copy Apex.sublime-package into that Installed Packages folder

Apex syntax is assigned to *.apex files by default. Hence *.cls file is likely to still use default Java?

If so, you probably want to …

  1. click the syntax name in status bar
  2. choose Open all with current extension as… > Java (Apex) syntax to permanently assign *.cls to Apex syntax.

Status bar should show Java (Apex) after all.

0 Likes

#16

Thank you so much @deathaxe finally it worked with all your help! Really appreciated your time!

0 Likes