Skip to content
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

Highlight @available/#available attributes #56

Merged
merged 5 commits into from Oct 17, 2015
Merged

Highlight @available/#available attributes #56

merged 5 commits into from Oct 17, 2015

Conversation

ghost
Copy link

@ghost ghost commented Sep 7, 2015

This adds the new (introduced in Swift 2) @available and #available attributes to the swift syntax file.

I chose to add this to the new swiftConditionalAttribute (since it's a conditional attribute that is used in if/guard statements) rather than the existing swiftAttributes (which are typically used to apply to functions/classes).

If you think that's wrong, I can easily update this.

Resolves #54

This adds the new (introduced in Swift 2) @available and #available
attributes to the swift syntax file.

Resolves #54
@aclissold
Copy link
Contributor

I think that the text within the parenthesis should be un-highlighted. @available(iOS 9.0, *) looks kinda weird because 9.0 isn't really a numeric literal, and * isn't really an operator. Do you agree?

@ghost
Copy link
Author

ghost commented Sep 7, 2015

@aclissold I do, however, Xcode highlights the 9.0.

I wonder if you can un-highlight inside the brackets. I'm not too familiar with vim syntax highlighting.

EDIT: I should also mention that I override some of the syntax defaults of this plugin, one of which is to link the Operator with Normal (as it should be 😛), so it looks the same for me as it does in Xcode.

@aclissold
Copy link
Contributor

Oh! Well if that's how Xcode does it… :P

As for swiftConditionalAttribute, hmm… reading the book, I guess it's not technically an attribute, because attributes "provide more information about a declaration or type," but #available is only used as a condition like guard let #available. The book calls it an "availability condition." Maybe something like swiftCondition or swiftConditionStatement?

And, maybe swiftPreprocessor should be renamed to swiftBuildConfiguration or swiftBuildConfigurationStatement?

And and, it looks like the line control statement #line is missing too—I had no idea that one existed!

@ghost
Copy link
Author

ghost commented Sep 7, 2015

Yep, I agree with your comments, I'll pick swiftConditionStatement for it then. 😄

About #line -- neither did I. I won't change the preprocessor stuff in this PR as it's not related to #54 but feel free to add a new ticket and I can pick it up or a PR if you want to add this in.

Akshay Hegde added 2 commits September 6, 2015 23:25
Conforming to Xcode, the syntax file now highlights platforms contained
within the `#available` condition.

It also now removes highlighting numbers and the "*" (i.e, symbol for
future platforms) that are contained within the `#available` condition
since they are not literal numbers or operator (thanks to @acclissold
for the idea)

Additionally, add tests to example.swift to demonstrate highlighting of
them.

References #56
@ghost
Copy link
Author

ghost commented Sep 7, 2015

@aclissold,

Thoughts on the newest commit?

I highlight the platforms, but skip highlighting the numbers and the *

Better now 😉?

Here's what it looks like with the latest commit (left is Vim, right is Xcode):

screen shot 2015-09-07 at 01 06 27

This adds the availability arguments described in the "Attributes"
chapter of the "The Swift Programming Language" book. Also expand the
list of platform names based on the Swift book.

References #56
@ghost
Copy link
Author

ghost commented Sep 7, 2015

Latest commit adds some niceties to @available like the attribute arguments for available.

(Boy this is more work for @available than I thought I would do 😛 but since @available is pretty useful, might be worth having this)

@aclissold
Copy link
Contributor

When I saw this issue a while ago, I thought about simply adding #available to the list of keywords, but then I thought about all this stuff for @available and how little I know about Vim highlighting, so thanks for stepping up to the plate :P

I like the stuff in the screenshot you posted buuuuuuuut I don't know how I feel about highlighting all the stuff in @available. It seems weird to me, Xcode doesn't do it, and it's especially jarring with my colorscheme lol:

screen shot 2015-09-07 at 11 34 23 am

@@ -142,6 +145,8 @@ syntax keyword swiftAttributes
\ @UIApplicationMain
\ @warn_unused_result

syntax keyword swiftConditionStatement #available
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be reasonable to group this in the "swiftPreprocessor" group?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought about that, but it's not really a pre-processor is it?

But if you're fine with it, I can make that change.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¯\_(ツ)_/¯ I'm fine with it either way. Maybe we could generalize that group since preprocessor is a misnomer anyways.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the Swift book calls them a BuildConfigurationStatement, which #available still isn't.

We could call it HashtagStatements or something :P.

Any thoughts on what we could call the group?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh, leaving it like this is fine.

Since Xcode doesn't highlight them, we shouldn't either. Keep the
highlight group so users can override it.

References #56
@ghost
Copy link
Author

ghost commented Sep 7, 2015

@aclissold: Oh! Well if Xcode doesn't do it 😛

Changed to remove the highlighting. 😄

I kept the highlight group still, so if anyone else wants, they could still get override the highlighting.

@keith
Copy link
Owner

keith commented Sep 7, 2015

@ajh17 re operator highlighting, feel free to submit a PR to not highlight them, although keeping the groups might be useful in the future.

keith added a commit that referenced this pull request Oct 17, 2015
Highlight @available/#available attributes
@keith keith merged commit 1e04ee9 into keith:master Oct 17, 2015
@keith
Copy link
Owner

keith commented Oct 17, 2015

Thanks guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants