-
Notifications
You must be signed in to change notification settings - Fork 29.5k
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
Indented code blocks in Hovers should use the correct language for the hover provider #11331
Comments
You can use the normal |
@jrieken I understand that, but it means figuring out where the code blocks are and rewriting them. Code is already doing Markdown parsing, so it seems a bit silly for us to have to do it too. All language extensions comments are probably going to have code blocks in the same language, so this seemed like it could save duplicated effort of us all writing our own markdown re-writer if comments are already markdown and contain code blocks? |
Maybe it's a formatting issue with GH but I really don't see any markdown in that sample, esp no code-block |
The lines indented by 4 spaces are code, but maybe it wasn't a very clear example. Here's a better (real) example; the Since this comment isn't written by us (extension author) but the end user, we can't ask them to add backticks (and it's also not the convention, as in Dart we know it's Dart). Surrounding the code blocks with backticks ourselves (in the hover provider) is possible but does mean we'll have to parse the Markdown on some level (because nested lists look a little like code blocks; they have blank lines before/after and are indented with 4 spaces). I'm not against rewriting the markdown ourselves, but I think a more elegant solution would be if we could just tell Code that all code blocks in this markdown should be considered Dart. If you don't think that's a good feature; that's fine; I just wanted to suggest it before I embarked on Markdown-parsing :-) Hope this is clearer!
|
Thanks for clarifying - I actually didn't know that you can format code blocks using space indentation... Now it makes sense to me. Thinking of a way to achieve this... We have this and it should be save to access the |
That means we won't allow to set the default (unless a really good idea for that comes up) but simply take the context as default |
Ah sorry, I should've provided a better example to start and maybe it would've been more obvious what I meant! I don't fully understand the last comment; do you mean you'll infer it from the language of the HoverProvider rather than letting us set it? (if so, that seems perfect to me!) |
Yeah - it would be the default when no |
Awesome; thank you! 👍 |
@octref It did work when I tested it in Insiders 18 days ago (see Dart-Code/Dart-Code#160 (comment)) but I haven't tested it recently. I'll make a note to give it another look tomorrow when I'm at a PC. |
@octref Indeed, it seems broken now; the colouring is all gone (was like that before I updated today - was probably a week old? and with todays version). |
@alexandrudima Is this due to the mode/tokenization changes you made? |
Yeah - looks like a regression from 04f43c3 where the fallback to the editor mode id got lost |
@jrieken reopening to assess if this is a possible candidate for the stable branch |
Removing the candidate for September stable since it is not a regression. |
Fixed in the latest. |
Hover works, code in comment doesn't. I'm looking at this file: https://github.com/angular/angular.dart/blob/master/lib/formatter/filter.dart Also wondering, is this something we should do? In the case of angular.dart there are also a lot of HTML code in comment. Marking them as dart doesn't make sense, but providing a custom way for author to say which lang their code is in doesn't sounds good either. |
@octref How should we know that half the comment is in dart and half the comment is in html ? |
@alexandrudima I thought the comment section are supposed to behave like hover, which marks everything as dart, in this dart file. I think we should only support github-style 3-backstick code blocks in comment. |
This issue was about falling back to the language currently being shown in the editor if the markdown code block doesn't specify one. |
Using @DanTup's dart extension this works for me. Looking at dart-lang/sdk's future.dart with an untrained eye. Marking verified. |
It would be really helpful if we could provide the language that should be used for code blocks in
Hover
s. Currently we can pass a string of markdown (where code will be uncoloured) or a chunk of text where the whole thing will be considered code in a language.In Dart, comments are already markdown, so we have code like this:
The string we get is exactly like that, minus the
///
. In order to get Dart highlighting code the code, we would have to split the document up, detect the code blocks and then createdMarkedString
s with the language set to Dart as each one. This is quite complicated because there are other things that are indented the same way with blank lines before/after (like nested lists). It would be great if we could just set the code language and pass markdown directly.The text was updated successfully, but these errors were encountered: