-
Notifications
You must be signed in to change notification settings - Fork 591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C#] Rewriting from scratch #93
Conversation
Thanks for the work on this! In order to reasonably consider these changes, we'll need some fairly extensive tests. These will consist of various C# files that are named a specific way, and include comments that indicate what scopes should be applied to what code. I recently added one in the C# folder for a bug someone reported. You can read more about syntax testing by scrolling to the Testing header on http://www.sublimetext.com/docs/3/syntax.html. Additionally, with dev build 3098 of Sublime Text, a "Performance" variant of the Syntax Tests build system was introduced. This will allow timing the highlighting of the currently open file using the syntax currently selected. Could you find some large-ish C# files and compare the performance of before and after your tweaks, and post them here? That will help us ensure that the regular expressions don't have any performance issues. |
Thanks for the feedback! |
Sorry, I did miss that! Those tests look like they cover a good amount of ground. If you could just include the existing test I created to ensure your version supports the same features, then I think we'll be in a good place. Do note that I changed "annotations" to "attributes" in the scope names. From what I can tell, "attributes" is the correct term for C#. I'm obviously happy to be corrected since C# is not something I have worked very much with. |
Attributes seems the "right" word. MSDN link about: https://msdn.microsoft.com/en-us/library/z0w1kczw.aspx I think you should include one test with the number suffixes because the sublime's version had the c/c++ LL "long long" but didn't have the "decimal" D |
I'm not sure it's a good idea to change the scope names to reflect the My point is that people creating themes shouldn't have to know all languages and their vocabulary. For example I think the C# 'attributes' should be named with a more conventional label. I used 'entity.name.tag' but it probably should be something like 'entity.name.annotation'. It would be really nice to have guidelines on scopes naming. The Texmate |
Regarding performances, I tested on a 2600 lines C# files made of a concatenation of several files:
So my version seems a little bit faster even if the syntax itself is bigger (weird, I would have expected the contrary). |
Any updates regarding the status of this PR? |
@buildersbrewery If I haven't closed an issue, it means that I am still intending to do something with it, or am waiting on changes from the author. In the case of this PR, I haven't yet gotten to it, but also there are a few things that would need to be resolved:
I have not reviewed the actual syntax definition yet to see if there are incompatible regex constructs, or if scope names are consistent with the other languages that have been rewritten recently (C++ is one of the most recent, non-trivial examples). |
Thanks @wbond for the feedback, What do you mean by incompatible regex? Is it just look-behind? Or are they other patterns I should avoid? |
@gwenzek My plan is to write them down, I have just been using my experience of rewriting a bunch of the syntaxes to figure out what needs to be written down. I've covered a number of the languages with C-like syntax, however there are a number that I have not yet. I will definitely provide feedback about the scope names once I have time to review this PR in-depth. Part of this whole process of getting all of the syntaxes up-to-date is to make the scopes more consistent so we can document them for syntax and color scheme authors. The Syntax Tests build system has a number of variants (ctrl+shift+b), one of which allows testing the compatibility with the new regex engine in Sublime Text. Moving forward we are removing all regexes that use incompatible features because the new regex engine is so much faster. This allows the highlighting of files and the indexer to run faster. There may be some edge cases of constructs from Oniguruma we aren't supporting in the new engine yet, so feel free to report those. We won't, however, be supporting lookbehinds, backreferences or atomic subgroups (those are generally unnecessary with the new engine). This has to do with the fact that the new engine is not a backtracking engine. |
@wbond I removed the backreferences, the syntax is now compatible with the new regex engine. I added back the tests that you added in the meanwhile but I don't have exactly the same convention for scopes. Also I'd like to have a scope for the My syntax does a great job at handling type parameters, variable declarations and method declarations. |
|
Really depends on the context. |
The current convention is to scope the dot as Most languages just use |
Thanks for the suggestion @FichteFoll , Also in C# 6 |
Improvements from sublimehq/Packages#93 . Removed backreferences. Renamed some scopes.
I took a look at this a few months ago (not the source, but the highlighting) and I wasn't pleased. However, revisiting recently, I am much happier with your syntax than the default. I did notice something odd with one specific case, though. If you don't use implicit typing on declarations with MyType foo = new MyType();
//^^^^ variable.other.type.cs
List<int> bar = new List<int>();
//^^ variable.function.cs Another thing that I think is a little odd is the handling of int? foo = 4;
// ^ keyword.operator.ternary
// It's not really a ternary operator.
string[] bar = {"baz"};
// ^^^^^ support.type.cs
// ^^ - punctuation
var foo = typeof(int);
// ^^^^^^ keyword.operator.reflexion
// Is this really an operator? Also, misspelling of "reflection" ? Overall, though, I think this is an improvement over the default syntax def. |
Thanks for testing @michaelblyons. In the current version of this PR I mark The |
cb22453
to
35c21bb
Compare
When creating an anonymous type, like:
The Maybe it would be possible to check whether
will still be correctly recognized as an array. |
I am pretty excited about this getting all the way through. I use it as my primary C# syntax now, but that has illuminated a couple more frustrations. Fragments of code containing >1 function are not highlighted correctly: string Permute(string input)
{
char[] charArray = input.ToCharArray();
Array.Reverse(charArray);
return new string(charArray);
}
// this function has no highlighting
string DontPermute(string input)
{
return input;
} This guy doesn't work as a fragment either: List<string> Frag
{
get
{
var list = new List<string>();
list.Add("foo");
list.Add("bar");
list.Add("baz");
return list;
} // <-- This and the next "}" are marked "invalid"
} Both work inside a |
Can we get it to scope the placeholders in |
@LoneBoco the regression regarding generics has been fixed. @michaelblyons Your first example is working with the current version. It has been added recently. |
@gwenzek Thanks! I notice that the first case is still weird with access modifiers. private string Permute(string input)
{
char[] charArray = input.ToCharArray();
Array.Reverse(charArray);
return new string(charArray);
}
// this function has no highlighting
private string DontPermute(string input)
{
return input;
} |
@michaelblyons thanks, the "visibility" modifiers weren't allowed inside code, so I added them. |
@gwenzek Thanks, regions and generics are looking good. public class B
{
public void Test()
{
int test = 1;
test = (test) ? 1 : 0;
}
} Found an odd issue with the ternary operator. It looks like it thinks the |
The cast detection is a bit nasty and only works with simple types between
parentheses.
I should probably improve it.
|
There is a slight inconsistency for generic types:
...
currently, the also, a similar situation with attributes:
the opening |
the Nullable shortcut
|
Is this going to get merged sometime soon? I've been using it for months. From time to time I find bugs (generally minor), but I hesitate adding them to this ticket because I don't want to slow it down any further. |
@michaelblyons I will try to spend some time this week going through this again. I believe I only got part-way through last time. |
I started going through this, but rather than make @gwenzek go through and apply a bunch of things I know need to change, I am going to merge it and make the changes that I know need to be made for consistency. Once that is done I can get feedback from anyone interested about tweaks where I may have changed something I shouldn't have. Hopefully this will be more efficient than a bunch more back-and-forth. BTW, thanks for your consistent effort on this @gwenzek, it is much appreciated! And thank you @LoneBoco and @michaelblyons for using it and providing feedback. |
Quick question: I presume the type |
RE |
Thanks @wbond for taking up that work ! I know that a lot of things still have to be done, but I haven't got much time for open source lately, |
Ok, so I just finished updating the rewrite to be consistent with our current scope guidelines. I added a ton of test assertions, and I think I checked the various bug reports in this PR, but I may have missed some. If you use C#, please put the new syntax through its paces, and provide snippets of any broken highlighting so we can get it fixed up for the next dev build. |
Hi, I started from scratch a new syntax for C# on a personal repository.
You'll find there several tests. I tried to use old scopes when they existed.
The principal features are:
[TestMethod]
$"{1 + 2}"
, "x?.y", ...I'll be happy to have some feedback on my work.