Closed aeschli closed 6 years ago
@acls - above you've mentioned that you don't think that Python-specific folding would be needed, however I'm struggling with the folding in Python when using multi-line strings that shouldn't be indented when printed out:
def print_text():
print("""
This unindented multi-line text doesn't get collapsed when collapsing the
function.
""")
Hello, Is there an update about how we can get users some nice folding working? I do not mean discussion about if it is ready. I am looking for feedback about code presentation, ui adjustments, environment state and editor context. So can we have a gathered thought around:
new ways of allowing this to visualize code
as some extensions already do some of these things, unifying some of the collective efforts would be welcomed. Hopefully this flow of information and communication can more balanced. Thank you. Good day.
@MichaelD1 I would say multiline text falls under the multiline docstrings or other things not based on indentation
category.
My point in my previous comments is that the broken indention-based folding #3353 should not be included in this language-aware folding issue.
Just receiver powershell 1.4.1, seems to recognize the region option now. `#region code
Is foldable now (do need a tab infront of code)
@Tuumke regions are not supported like they should be in the current release of PS Extension or Code.
If you don't indent the region tags it will fold, but most folks will put region tags lined up with the other code...which is supported in ISE.
This currently works:
#region MyReg
Get-Process -name NotHappening
#endregion
But this is not:
#region MyReg
Get-Process -name NotHappening
#endregion
It's not the region which is working but generally indentation is working. See below.
It would be really helpful to have this feature. Is there any news yet on its implementation?
Hello, Can there be more discussion of what thoughts are being kicked around behind the scenes as to allow extensions or users to create language aware editor folding and markers? The interest is in both the implementation path and the final result.
For multi root support there a skype meeting (recorded) and mocks that were kicked around to get feedback and let the community know there is some progress being made. That would be nice here as well. Given how important this is to the primary use case of this software, lets keep it transparent (good or bad).
In the smallest aspect of maintaining discussion, talking about how the coding and concepts of the currently implemented indentation model would give people opportunities for constructive pull requests for new ideas. Thank you. Good day.
Folding sections within a Markdown document is another example. I'd love to be able to show/hide various Markdown sections as you would in Emacs Org mode.
Proposal for a new style folding in #26757 is not exactly "language aware". But still may be relevant to this issue.
You are correct, region folding does not necessarily require language awareness. Therefore I opened #12146 to a separate issue. Please add your thumbs up there so that this feature gets more priority.
interesting extension that does part of what #region functionality should do: bookmarks maybe it can evolve to what we want here?
VS Code is an amazing and awesome free editor. But I will pay $$$ right now to you or the charity of your choice if you please please fix the folding for PowerShell regions. Seriously. It's killing me.
THANK YOU for fixing the code folding for PowerShell regions in the 1.17 release! And I am a man of my word: I just donated to the Puerto Rico hurricane Maria relief effort.
I hope language extensions will get the ability to add custom folding at some point. C# has several other places that we'd like to fold in order to reach parity with VS which require knowledge of the parse tree. For example, "#if", "#else", "#endif", using directives, etc.
@DustinCampbell And don't forget about multiline verbatim strings. PowerShell has a similar feature (here strings) that mess up code folding.
Tested on Windows 10 and it is working great for me. It is nice that indentation isn't required in between the #region and $endregion pairing in PowerShell. Thanks.
Totally agree with @rkeithhill . When VS Code can work properly with here strings
in PowerShell
it will be my default editor. Until that's implemented I still have to use the Powershell ISE
. Otherwise some code might break and that's not acceptable in a production environment.
But again, thanks for the addition of region
aware folding. It's a first step in getting an amazing editor for Powershell
.
When I can fold my functions and html tags like I do in VS 2015? Or it's a kind of taboo. Just tell me.
Well, the folding in C/C++ still not working correctly.
No taboo at all, there were just always other issues & features with higher pressures to implement. But we are getting there. Please keep adding 👍 to the description, that's the way we prioritize.
Hello, @LeThiHyVong the current folding that was added is based on a loose pair of single markers defined by a regular expression in the language configuration file. It is now mostly just used with language that either directly have a notion of a code region (like C# or VB) or for some other languages that have been using a comment marked version that has similar support in other editors (JavaScript, C, F#). There needs to be more discussion on how to extend to capture more markers and how to name and group them. Thank you. Good day.
What have to be done to make it work with CSS? (To have regions in css file without changing the depth of styles themselves and messing with linter.)
Hello, @KillyMXI Remember to look at #12146 for editor region specific folding. It just happens to be that a few languages (like C# and VB.Net) have it as a syntactic element. Most are using a line level regex lookup. By common practice, the scans are against language comments for possible folding regions. It does not know anything special about a language.
I left another comment in the other issue with a straightforward but non user friendly way to add this for yourself. Thank you. Good day.
Love the new region folding. Could you add support for 'bat' files?
As a workaround I added this to my C:\Program Files\Microsoft VS Code\resources\app\extensions\bat\language-configuration.json
file
"folding": {
"markers": {
"start": "^\\s*::#region",
"end": "^\\s*::#endregion"
}
}
@MichielVanderlee Please make a PR....
Hello, @MichielVanderlee please also include the "REM" comment as an or (using "|" in regex) option. Since it is the official way. REM versus :: versus %= =% is worth looking at. Thank you. Good day.
It's still not working for the opening comment <#
and the closing comment #>
in PowerShell
code.
Example:
function Get-WindowsVersion {
<#
.SYNOPSIS
List Windows Version from computer.
.DESCRIPTION
List Windows Version from computer.
.PARAMETER ComputerName
Name of server to list Windows Version from remote computer.
#>
Write-Output 'Success'
}
Is it possible to add folding for this too?
Hello, @DarkLite1 there is still no news about folding because of language syntax nor semantics. So a problem with folding the contents of a single block comment are that it can span multiple lines and some people style it differently like inline starting or trailing marker. Were you looking to fold all block comments, regardless its content?
If you were mentioning about the language agnostic editor folding, then editor folding is in another issue.
@pr-yemibedu Yes, I was looking to fold everything between <#
and #>
regardless of its contents. At least, this is what is needed for PowerShell
. I don't know about other languages.
I would initially consider folding all comments as language aware fold logic. But I also think that this is something very doable with the logic already specified. There would a need to have some style constraints to be good for folding:
blockComment[0] <> blockComment[1]
That would allow for the code to just attempt to grab the existing markers comments.blockComment
array and push the first pair onto an array of patterns:
function escapeRegExp(str) {
return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
}
let comments = { "blockComment": ["(*", "*)"] }
let commentStart = escapeRegExp(comments.blockComment[0])
let commentEnd = escapeRegExp(comments.blockComment[1])
let commentPair = `(^\\s*${commentStart})|(?:${commentEnd}\\s*$)`
let commentPattern = new RegExp(commentPair)
patterns.push(commentPattern)
So the question is when can we get to the current logic to support lists of pattern pairs @aeschli? Hope this does not feel like spam, just think it is doable but involves changes you might want to do yourself instead of by PR.
@pr-yemibedu Your comment doesn't really apply to a lot of cases.
the lead marker can not have non whitespace in front of it
What about inline comment blocks? In PowerShell, for example, it's not uncommon to have a comment based help block indented with the function block.
the tail marker can not have non whitespace after it
In shell languages, redirection of string blocks can occur (again, PowerShell, here-strings)
the lead and tail marker are on different lines
Back to point one, where there can be a open/close comment glyph on the same line
this would only apply to languages that defined block comments and blockComment[0] <> blockComment[1]
Makes sense, but the points above are still valid.
Hello, All of the things I mentioned were solely for comments. They were about languages that support block comments using an true syntax construct. It was not about languages that ignore artifacts that people can use as comments.
\s
. So an comment block that starts on its own line but is indented would be fine. If you need your block comment to start at the end a code line, that would both look odd and not benefit.I just want to make sure we are on the same page of what my proposal was entailing. It was a way to get some of the comments to fold that were not already being handled by another extension.
Please continue to comment to help flesh out use cases and understandings. Also , if you can include small code snippets that demonstrate how you would like things to look would help. Thank you. Good day.
Do we have progress on #37494 ?
Outside the function of folding failure
Maybe I missed something ... I recently migrated my javascript project from netbeans to visual studio code ... in netbeans we use
//<editor-fold defaultstate="collapsed" desc="getControleur">
...
//</editor-fold>
for defining regions ... I saw I could modify javascript-language-configuration.json to
"folding": {
"markers": {
"start": "^\\s*//\\s*(?:(?:#?region\\b)|(?:<editor-fold\\b))",
"end": "^\\s*//\\s*(?:(?:#?endregion\\b)|(?:</editor-fold>))"
}
}
SO that the existant region markers can be reused ... however it seems Visual studio code does not have a defaultstate ? It would be an advantage to be able to reuse also defaultstate in region folding
@Ptiloup Please file a new issue. Maybe you are looking for something like #36002.
Any update on the folding of here strings @" My here string "@
or block comments <# Block comment #>
for PowerShell
editing? I don't want to be rude, but this question is on the table since February 2016. It would really be nice to see some progress here...
This place is graveyard.
This has come up for Dart:
https://github.com/Dart-Code/Dart-Code/issues/583
Multi-line strings tend to go back to column 0 (no indenting) so the folding just stops there. My language server can provide me all of the folding region data, I just don't have a way of providing it to Code to use.
Atom's code folding based on indentation. But the next release (1.25) new parsing system Tree-sitter is added. I tried roughly and it's ok on small files. May VSCode follow? https://github.com/atom/atom/pull/16299
Update: Seem like VSCode team plan to work on their own https://code.visualstudio.com/updates/v1_21#_folding
I saw that a new experimental API was introduced in VS Code 1.21. Thank you for looking into this.
Are there any plans to give control as to which line is shown after the content is folded? For example, in VS Code, the source files look like this at the top:
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Current folding behaviour:
/*--------------------------------------------------------------------------------------------- ...
Proposed folding behaviour:
... * Copyright (c) Microsoft Corporation. All rights reserved. ...
export interface FoldingRange {
/**
* The start line number
*/
startLine: number;
/**
* The end line number
*/
endLine: number;
/**
* The line to show when the region is folded. If this is
* unspecified, then startLine will be shown.
*/
visibleLine?: number;
/**
* The actual color value for this folding range.
*/
type?: FoldingRangeType | string;
}
@rcjsuen your request is similar to https://github.com/Microsoft/vscode/issues/19912
Thank you for the info, @unional.
I also found #31966.
Hello, There would need to be a really strong formatter to shrink the excessive parts of the comments to get at such useful information. That may not be the exact case now, but I wanted to brain dump it. Most typical, lines with at least one letter or number is a high candidate for keeping to favor that useful preview style. It would handle most scenarios. Thank you. Good day.
code fold logic have a question
@SunOfHomeBoy Please file a separate issue with the VSCode version and the sample code.
Dear all,
I think I have not seen this example here yet. (Please let me know if other post discussed this already)
Hello, @autodrive , It not a new notion to the old problem of only having indentation as the folding signal. There is now experimental syntax support possible in the mainline. It needs extension author help for the vast languages out there. Only HTML, JSON, Markdown, CSS, LESS and SCSS come available out of the box. So hopefully there can be a resolution to many of these scenarios issues. Thank you. Good day.
The current implementation of folding uses an indentation based folding strategy that is unaware of the language it works on. Knowledge on the underlying language allows us to solve the following requests: