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

Add editor formatting service to auto-deindent closing brackets #3313

Merged
merged 10 commits into from
Sep 6, 2017

Conversation

saul
Copy link
Contributor

@saul saul commented Jul 7, 2017

At no point in this GIF do I Shift-Tab to de-indent. Closing braces automatically deindent to the same indentation level as that of the opening brace.

It performs the de-indent check on Enter, and when one of ), ] or } is pressed.

auto deindent

Copy link
Contributor

@cartermp cartermp left a comment

Choose a reason for hiding this comment

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

This is great. Just have two suggestions. Not sure if the scenario implied by them is realistic though.

asyncMaybe {
let! options = optionsOpt

let line = sourceText.Lines.[sourceText.Lines.IndexOf position]
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this is realistic or would ever get hit, but max 0 (sourceText.Lines.IndexOf position) would be useful.

Perhaps this is just me being paranoid after #3180.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IndexOf throws if the position isn't within the text, but as Roslyn has already supplied us with the position I think it's impossible that we can't find the line in the source text (also supplied by Roslyn).

|> Seq.takeWhile ((=) ' ')
|> Seq.length

let startIndent = indentChars sourceText.Lines.[sourceText.Lines.IndexOf leftSpan.Start]
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above, or perhaps check this before hand if a startIndent of 0 would cause trouble?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tested with startIndent 0 and everything's fine :)

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@cartermp
Copy link
Contributor

cartermp commented Jul 8, 2017

Also, perhaps making this be driven by an editor option (and on by default) would also be good if that's possible. I imagine some people would like to turn it off if they prefer a more plain editor.

@saul
Copy link
Contributor Author

saul commented Jul 8, 2017

Phillip I've set it so that smart indentation is only done if the indentation style is set to 'Smart' in the editor settings. However I think by default it's set to 'Block' and I think we should move everyone over to this style by default - any thoughts as to how we could do this?

@vasily-kirichenko
Copy link
Contributor

I'm for as smart style as possible by default. After writing some Kotlin in Inellij F# VS editor feels annoyingly dumb.

@cartermp
Copy link
Contributor

cartermp commented Jul 8, 2017

@saul This line seems like it should be setting it already; if that's not the case, then we definitely have a bug in registering the language service.

@cartermp
Copy link
Contributor

cartermp commented Jul 8, 2017

@dotnet-bot test this please

@saul
Copy link
Contributor Author

saul commented Jul 8, 2017

Phillip it's shown as an option but it's not the default

@cartermp
Copy link
Contributor

cartermp commented Jul 8, 2017

Ah, I was mistaken in thinking this was what should also set it. Clearly not the case based on the docs for that. I've no idea where this would be set. Isn't there a common place where we're setting some of the newer settings which were added?

@forki
Copy link
Contributor

forki commented Jul 9, 2017

This is great. Is this something that other editors can use as well? /cc @Krzysztof-Cieslak

@forki
Copy link
Contributor

forki commented Jul 9, 2017

Ok everything is in vsintegration. So that's a no. ;-(
Anyway: cool feature. Thanks a lot

@vasily-kirichenko
Copy link
Contributor

I'm still waiting when anything from Code can be used in VS.

@forki
Copy link
Contributor

forki commented Jul 9, 2017

Most of the fable, react, react native tooling is develop in code. That stuff will flow to VS in vnext. Also a lot of the paket / netcore integration stuff. It's all done so that all editors benefit

@Krzysztof-Cieslak
Copy link
Contributor

I'm still waiting when anything from Code can be used in VS.

I'm still waiting for features be implemented in FCS instead of being coupled with VS. At least in our case features are shared between xplat editors using FSAC.

@dsyme
Copy link
Contributor

dsyme commented Jul 10, 2017

I'm still waiting for features be implemented in FCS instead of being coupled with VS. At least in our case features are shared between xplat editors using FSAC.

@Krzysztof-Cieslak I've a WIP integration of a large amount of work into the FCS repo , where we will do final testing on FCS (which actually caught some issues), add some documentation and a release.

After this integration the whole test/release process should be easier. We will also accept contributions directly to FCS and cherry-pick them into VS if people have a strong preference to contribute them directly to FCS.

@Pilchie
Copy link
Member

Pilchie commented Jul 10, 2017

@jasonmalinowski do you know how to set the default value for indenting for a language service to "Smart"?

@Krzysztof-Cieslak
Copy link
Contributor

Krzysztof-Cieslak commented Jul 11, 2017

@dsyme, I think I do understand the workflow ;) My point was about the fact that whole logic of this feature (and many others) is implemented in vsintegration layer that's not part of things ported to FCS, and is directly using Roslyn APIs which makes porting to any other editor difficult. What is totally fine, but given this fact Vasily's comment was not really fair, IMHO.

Anyway, great feature. 💯

@vasily-kirichenko
Copy link
Contributor

I meant that VF(P)T -> Ionide should not be one way road. If you like this feature be available in Ionide, make a PR here, moving the logic to FCS. People here don't care about Ionide, just as you don't care about VS.

@Krzysztof-Cieslak
Copy link
Contributor

People here don't care about Ionide, just as you don't care about VS.

You don't care about Ionide. Pretty sure lot of contributors and maintainers of this repo care about xplat tooling

@vasily-kirichenko
Copy link
Contributor

OK, it's me who don't care :) Anyway, what about the PR?..

@dsyme
Copy link
Contributor

dsyme commented Jul 12, 2017

... don't care about Ionide..

I care about Ionide, very very much. I use it all the time and am slowly trying to learn how to contribute to it.

You don't have to care about Visual Studio IDE Tools to contribute to F# bits in this repo (except to make sure they continue to compile and pass CI tests as part of your PR).

If you like this feature be available in Ionide, make a PR here, moving the logic to FCS.

I agree with this

@KevinRansom
Copy link
Member

@vasily-kirichenko @Krzysztof-Cieslak @dsyme. I would love to have a plan where Ionide and VS Tools shared code. However, I am not smart enough or knowledgeable enough to figure out how that would work. Perhaps one day we will get there ... for sure Ionide is something we care about.

@cartermp
Copy link
Contributor

FYI - asked around about how to set this as the default. Lots of folks taking vacations this time of year, but I'll follow up on that again. I'm fine with taking this for now and then creating a separate issue for Smart Indent being the default.

@saul
Copy link
Contributor Author

saul commented Jul 21, 2017

Thanks Phillip. I'm also on vacation now so I can't get around to fixing the tests until week after next.

@cartermp
Copy link
Contributor

Sounds good. I'll flag this for follow-up ~1.5 weeks for now. Have a good time!

@saul
Copy link
Contributor Author

saul commented Aug 23, 2017

It's worth noting we need a way to move everyone's 'Tab Style' to 'Smart' (as C# does) - otherwise people won't get any kind of auto indentation. Note that then we'd match C#'s behaviour.

@saul
Copy link
Contributor Author

saul commented Aug 23, 2017

cc @KevinRansom @cartermp see comment above

@KevinRansom
Copy link
Member

@saul without enabling by default, discovery will be hard, so I agree it should probably be the default. However, people often dislike default changes, even when the change is useful stuff.
Lets get it in and road test this for a few months, and make sure the experience is right and switch over to having smart as the default in VS2017.5.

Does that make sense?

@saul
Copy link
Contributor Author

saul commented Aug 23, 2017

It's not a default change per se as the current behaviour will be moved to only act that way if 'Smart' is enabled. So to the end user indentation will work exactly the same, except it will de-indent too (that's what this PR is adding).

@KevinRansom
Copy link
Member

@saul I'm sorry I misunderstood the question. Making the auto de-indent "smart indent only" only seems right. I think we should consider making smart the default, when we are sure the experience is solid.

Does that help?

@cartermp
Copy link
Contributor

The question is how we do that. It's the default for me on a fresh installation of VS, and I've never gone in to set it myself, which is why that setting is confusing to me.

The experience with this PR (and @xuanduc987's) is great, IMO. The editor feels smart.

@KevinRansom
Copy link
Member

It's a VS setting thingy ... there's some way of setting defaults in the internal VS codebase. I seem to remember Lincoln working it out ages ago, in order to ensure that tabs as spaces is set. I expect Johnathan or Brett know the magic goo.

@KevinRansom
Copy link
Member

@dotnet-bot Windows_NT Release_ci_part1 Build please

@saul
Copy link
Contributor Author

saul commented Aug 24, 2017

@KevinRansom I know about the failing test cases.

Also I think there's a way that we can make Jenkins outside more readable - is there a reason why we aren't parsing the NUnit test report XML? I may open a new PR that makes reading CI failures palpable.

@forki
Copy link
Contributor

forki commented Aug 24, 2017 via email

@realvictorprm
Copy link
Contributor

This looks super useful, @saul is this in such a state that I can safely install it 😝 ?

@saul
Copy link
Contributor Author

saul commented Aug 24, 2017 via email

@cartermp
Copy link
Contributor

@dotnet-bot Windows_NT Release_ci_part1 Build please

Timeout on the CI server...

@cartermp
Copy link
Contributor

@saul An error in the log here:

=> Tests.Service.ProjectAnalysisTests.Test Project21 whole project errors
15:56:45 Project21 error: <<<This expression was expected to have type
15:56:45     'int'    
15:56:45 but here has type
15:56:45     'string'    >>>
15:56:45 Project21 error: <<<Invalid value>>>

@abelbraaksma
Copy link
Contributor

Thanks for this change, this and other work on Smart indent is really very welcome. As an aside, all this work smart indent fixes other, often closed-without-solution issues like #1588, #1986 (where it was still believed smart indent didn't exist, probably true at the time) and #1980.

Still WIP, other tests still broken
@saul
Copy link
Contributor Author

saul commented Sep 2, 2017

@cartermp when this goes green it's ready to merge.

@saul
Copy link
Contributor Author

saul commented Sep 2, 2017

@dotnet-bot please test Windows_NT Release_ci_part2

@saul
Copy link
Contributor Author

saul commented Sep 4, 2017

@KevinRansom @cartermp this is ready to merge

@KevinRansom
Copy link
Member

@saul
Thanks for this, it's great.

Kevin

@cartermp cartermp merged commit a6cfc81 into dotnet:master Sep 6, 2017
nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Jan 26, 2022
…et#3313)

* Add editor formatting service for auto-deindent

* Minor refactor of the indentation service - do not indent after 'function'

* Only use smart indentation if indent style is set to 'Smart'

* Fix broken unit test build

* Implement review comments, fix build

* Fix some broken brace matching tests

Still WIP, other tests still broken

* Fix failing indentation tests

* Add formatting service tests

* Add more brace matching tests

Fixes dotnet#2092
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.