You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support file language detection with more than the first line #69868
We need a way to associate ARM template files with a language ID separate from the current JSON language. Unfortunately, the existing firstLine filter for languages doesn't suffice for ARM templates (or for any other sub-JSON support). ARM template files are .json files and generally look like this:
The $schema value is the key to knowing if it’s an ARM template (technically it could be anywhere in the file although it’s usually at the top like this). So we need a way to check further into the file than the first line. Thanks!
Reacted by William Warriner, Kevin DeJong, Gordon Smith, Stephen Weatherford, Hikaruxy, Rishav Dhar and Anton Krasovsky
I would like to see this resolved as well. I'm looking at implementing better support for editing Swagger/OpenAPI JSON files. However, there are two major versions of the standard with different JSON Schemas, and the recommended way to tell one from another is to check values of the top level "swagger" or "openapi" fields.
This will not work (today) even if we had a property to match on the first 3 lines because of #53350. Unless the file extension is different and no registration exists for the file extension, we would not pick up such a contribution. The contributions based on content currently only win if no other registration was picked based on filename, path or extension but in this case our own JSON extension would always be prioritized.
Today we have the possibility to contribute languages based on firstLine. This is not enough for Azure resources that have marker text spanning multiple lines. We should have a new contribution mechanism preamble that is defined as the first lines of a file (e.g. 3-5). We still need to decide if we require the target text to be fully included in these lines or if we allow glob matching too as we do with firstLine.
Allow language extensions to override built in extensions by more than one rule
Even if we allow this new preamble matcher, an extension will not be able to overrule our built in JSON extension because we always first try to match on file extensions and only ever consider textual content if no extension matches based on the file name and extension.
To enable this, we would need a new way for extensions to contribute a language based on multiple conditions, not just one. For example:
I think we have reached the limits of what can be implemented with a descriptive approach. I suggest the extension:
activates on language:json
listens on text document open
checks if the opened text document is JSON
checks if it has "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"
changes the language from JSON to some new language via languages.setTextDocumentLanguage
this will trigger a document close and a document open event, but that's OK
alexandrudima How would this approach play with built in 'json-language-features' extension? Currently it supports two languages 'json' and 'jsonc'. Will it have to be updated to include new language IDs?
alexandrudima This proposal looks good to me. However, in order to supply JSON Schemas for the documents which lack "$schema" attribute, I propose to extend 'json-language-features' extension, to expose API to supply schemas. I've opened a PR #73424 which should give an idea to what I'm looking to do. I would appreciate a feedback on it.
changed the title [-]file language detection with more the first line[/-][+]Support file language detection with more the first line[/+]on Oct 24, 2019
This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.
changed the title [-]Support file language detection with more the first line[/-][+]Support file language detection with more than the first line[/+]on Nov 6, 2020
This feature request has not yet received the 20 community upvotes it takes to make to our backlog. 10 days to go. To learn more about how we handle feature requests, please see our documentation.
🙁 In the last 60 days, this feature request has received less than 20 community upvotes and we closed it. Still a big Thank You to you for taking the time to create this issue! To learn more about how we handle feature requests, please see our documentation.
Activity
GordonSmith commentedon Mar 24, 2019
Quick "me too" and not limited to JSON - think about XML at the same time...
ak1394 commentedon Apr 23, 2019
I would like to see this resolved as well. I'm looking at implementing better support for editing Swagger/OpenAPI JSON files. However, there are two major versions of the standard with different JSON Schemas, and the recommended way to tell one from another is to check values of the top level "swagger" or "openapi" fields.
bpasero commentedon Apr 25, 2019
This will not work (today) even if we had a property to match on the first 3 lines because of #53350. Unless the file extension is different and no registration exists for the file extension, we would not pick up such a contribution. The contributions based on content currently only win if no other registration was picked based on filename, path or extension but in this case our own JSON extension would always be prioritized.
bpasero commentedon May 6, 2019
After talking to Martin Aeschlimann (@aeschli) and Erich Gamma (@egamma) here is a proposal also based on #10915 and #53350
Introduce a new
preamblematcherToday we have the possibility to contribute languages based on
firstLine. This is not enough for Azure resources that have marker text spanning multiple lines. We should have a new contribution mechanismpreamblethat is defined as the first lines of a file (e.g. 3-5). We still need to decide if we require the target text to be fully included in these lines or if we allow glob matching too as we do withfirstLine.Allow language extensions to override built in extensions by more than one rule
Even if we allow this new
preamblematcher, an extension will not be able to overrule our built in JSON extension because we always first try to match on file extensions and only ever consider textual content if no extension matches based on the file name and extension.To enable this, we would need a new way for extensions to contribute a language based on multiple conditions, not just one. For example:
(this format is just an idea taken from #10915 and is up for debate)
The rule would be that extensions with multiple conditions that match are prioritized over others that only define single conditions.
//cc alexandrudima
alexdima commentedon May 7, 2019
I think we have reached the limits of what can be implemented with a descriptive approach. I suggest the extension:
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"languages.setTextDocumentLanguageak1394 commentedon May 7, 2019
alexandrudima How would this approach play with built in 'json-language-features' extension? Currently it supports two languages 'json' and 'jsonc'. Will it have to be updated to include new language IDs?
alexdima commentedon May 7, 2019
No changes would be needed to the JSON extension.
ak1394 commentedon May 7, 2019
alexandrudima This proposal looks good to me. However, in order to supply JSON Schemas for the documents which lack "$schema" attribute, I propose to extend 'json-language-features' extension, to expose API to supply schemas. I've opened a PR #73424 which should give an idea to what I'm looking to do. I would appreciate a feedback on it.
5 remaining items
[-]file language detection with more the first line[/-][+]Support file language detection with more the first line[/+]vscode-triage-bot commentedon Nov 6, 2020
This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.
Happy Coding!
[-]Support file language detection with more the first line[/-][+]Support file language detection with more than the first line[/+]vscode-triage-bot commentedon Dec 27, 2020
This feature request has not yet received the 20 community upvotes it takes to make to our backlog. 10 days to go. To learn more about how we handle feature requests, please see our documentation.
Happy Coding!
vscode-triage-bot commentedon Jan 6, 2021
🙁 In the last 60 days, this feature request has received less than 20 community upvotes and we closed it. Still a big Thank You to you for taking the time to create this issue! To learn more about how we handle feature requests, please see our documentation.
Happy Coding!