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

Feature/upgrade powershell #1213

Merged
merged 45 commits into from
Jun 28, 2019
Merged

Feature/upgrade powershell #1213

merged 45 commits into from
Jun 28, 2019

Conversation

aaroneg
Copy link
Contributor

@aaroneg aaroneg commented Jun 21, 2019

This should fix or make moot the following issues:
closes #640
closes #966
closes #1041
closes #1208
closes #1209
closes #1210

This should make it unnecessary to merge:
closes #967
I would like to thank @miparnisari for caring enough to open a PR ❤

It does NOT fix, but partially addresses:
#1025 , and it would be nice to get some more expert help on this one.

It doesn't handle two types declarations on the same line for some reason, and perhaps someone more accomplished with rouge can help me figure out why. Perhaps @jneen ? ( See the first few lines of the 'Add-Extension' function in the sample output )

It also adds support for comment based help ( https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comment_based_help?view=powershell-6 )

@pyrmont pyrmont added the needs-review The PR needs to be reviewed label Jun 21, 2019
@aaroneg
Copy link
Contributor Author

aaroneg commented Jun 21, 2019

( And thanks to @gmckeown for #660 )

@ashmaroli
Copy link
Contributor

@aaroneg The comment closes #1210 has to be within the opening post for GitHub to actually close the issue when this merges..

@aaroneg
Copy link
Contributor Author

aaroneg commented Jun 21, 2019

Ah thanks @ashmaroli

Copy link
Contributor

@pyrmont pyrmont left a comment

Choose a reason for hiding this comment

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

Let me know if you have any questions about the comments!

@pyrmont pyrmont added author-action The PR has been reviewed but action by the author is needed and removed needs-review The PR needs to be reviewed labels Jun 21, 2019
@gmckeown
Copy link
Contributor

gmckeown commented Jun 21, 2019

@aaroneg Is the removal of built-ins highlighting deliberate?

Ignore, as I figured out what you were doing here now.

@pyrmont
Copy link
Contributor

pyrmont commented Jun 26, 2019

@gmckeown Sorry, bringing the discussion back to the main PR since we've resolved the other stuff. I discovered that a problem with my lexing logic was the parsing of attributes. I've since fixed this but do not think the list in ATTRIBUTES is complete. It doesn't cause any errors since the lexer will just assume anything it doesn't recognise as an attribute is a type but it's a little incorrect. What do you think? I'm honestly at this point inclined just to leave it as-is and wait for people to complain before fixing it.

@jpmarceau Sorry to drag you into this but since I now know you use the PowerShell highlighting, too, do you have any thoughts?

@gmckeown
Copy link
Contributor

I ... do not think the list in ATTRIBUTES is complete. It doesn't cause any errors since the lexer will just assume anything it doesn't recognise as an attribute is a type but it's a little incorrect. What do you think? I'm honestly at this point inclined just to leave it as-is and wait for people to complain before fixing it.

It does contain all of the cmdlet binding attributes, so I guess the question is whether you're expecting other attributes to be included?

Does parameter belong in here? VSCode, for example, treats parameter more like a type and certainly differently to a cmdlet binding attribute:

image

It is formally considered an attribute, but should we distinguish between cmdlet binding attributes and function parameter attributes? They're certainly not interchangeable -- you can't put parameter inside cmdletBinding and you can't put confirmImpact as an attribute of a function parameter.

@pyrmont
Copy link
Contributor

pyrmont commented Jun 26, 2019

@gmckeown We also have CmdLetBinding as an attribute, though. Should it and Parameter both be taken out?

@gmckeown
Copy link
Contributor

gmckeown commented Jun 26, 2019

We also have CmdLetBinding as an attribute, though. Should it and Parameter both be taken out?

I think yes. Did @aaroneg include CmdletBinding in there initially? Maybe there was a reason?

rule %r/(function)(\s+)(?:(\w+)(:))?(\w[-\w]+)/i do
groups Keyword::Reserved, Text::Whitespace, Name::Namespace, Punctuation, Name::Function
end
rule %r/(?:#{AUTO_VARS})\b/i, Name::Builtin::Pseudo
Copy link
Contributor

Choose a reason for hiding this comment

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

@pyrmont I just want to re-iterate that I think this is an over-simplistic way of identifying the automatic variables -- I did it as a quick test locally, but it's not going to correctly highlight them in strings and possibly in other contexts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah. Good to know. I should probably move the test to the :variable state.

@pyrmont
Copy link
Contributor

pyrmont commented Jun 26, 2019

@gmckeown It was in there from the beginning (@aaroneg took it out in the initial commit but he later put it back). I think we can take it out and highlight it like VSCode does.

@gmckeown
Copy link
Contributor

I think we can it and highlight it like VSCode does.

That works for me!

@pyrmont
Copy link
Contributor

pyrmont commented Jun 26, 2019

@gmckeown I'll see if @jpmarceau has any thoughts. He very quickly noticed an error in the PowerShell lexer in 3.5.0 so might have a helpful perspective. It's looking pretty close to merging to me.

@gmckeown
Copy link
Contributor

@pyrmont Just spotted an oddity in the visual sample with the latest lexer:

image

Not sure why Position is a Name.Builtin.Pseudo when the other items are Keyword.Type. Is it this rule in bracket handling:

       rule %r/([A-Za-z]\w+)/ do |m|
          if ATTRIBUTES.include? m[0]
            token Name::Builtin::Pseudo
          else
            token Keyword::Type
          end
        end

I guess include? is doing a partial match and is picking up PositionalBinding?

@pyrmont
Copy link
Contributor

pyrmont commented Jun 27, 2019

@gmckeown I'm away from my computer but I'm not sure. I'll have a look later this evening!

@pyrmont
Copy link
Contributor

pyrmont commented Jun 27, 2019

@gmckeown I'm a moron. I was mashing the elements in the ATTRIBUTES array together but I don't want to do that any more given how it's being used now. I've fixed and that's solved the problem. And you were right: the way String#include? works was causing it to do a partial match.

@pyrmont pyrmont added needs-review The PR needs to be reviewed and removed author-action The PR has been reviewed but action by the author is needed labels Jun 27, 2019
@@ -14,8 +14,8 @@ class Powershell < RegexLexer

# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_commonparameters?view=powershell-6
Copy link
Contributor

Choose a reason for hiding this comment

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

For accuracy, should now change this comment to:

# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_cmdletbindingattribute?view=powershell-6

Copy link
Contributor

Choose a reason for hiding this comment

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

Have made the change (only found out that GitHub allows a direct edit and commit from the UI...).

@jpmarceau
Copy link

@pyrmont thanks for asking but sadly I can't really offer much input here. I quickly spotted the issue with 3.5.0 because it was causing my deployment to fail, but other than that I don't have enough expertise with your project to be of much use.

@pyrmont
Copy link
Contributor

pyrmont commented Jun 28, 2019

@jpmarceau No problem! Just wanted to check :)

@pyrmont pyrmont merged commit f1125f3 into rouge-ruby:master Jun 28, 2019
@pyrmont
Copy link
Contributor

pyrmont commented Jun 28, 2019

Thanks to everyone that contributed as part of this PR. We have a far more robust lexer as a result :)

If you spot any problems, please always feel free to file an issue!

@aaroneg aaroneg deleted the feature/upgrade-powershell branch June 28, 2019 01:52
@pyrmont pyrmont removed the needs-review The PR needs to be reviewed label Jun 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants