-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Expose 'change language' as command #1800
Comments
@alexandrudima @jrieken ping |
there should be a command that allows to change the mine, like from the status bar. |
@jrieken Are you saying there is already a way to do it by sending a command? |
yes and no. there is command but I believe it won't work the way it should. |
It should be like |
I think this action does not exist the way wanted, it just opens the mode picker. Having a way to change the mode on a opened document is maybe something that should be exposed as API? |
we cannot make it a setting because by the logic of the document API and synching it will remove that document and create a new one. like calling |
Any update on this issue? I just started using vscode after many years on sublime and the lack of modeline support is hugely annoying...enough to switch back. Also, this issue ought to be merged with: |
@markeissler This is about adding API to allow extensions to change the mode. I believe you are looking for a user interaction, right? There is the mode switcher at the bottom of the editor |
No, this is exactly about the API. It's standard practice to use vi/vim/emacs modeline indicators in header comments of a file so that an editor can override whatever it's best "guess" is to select the correct language. Usually, the guess is based on the file extension but it has become common for certain files not to carry a filename extension (the OP started this thread with the example of a Vagrantfile, which is actually a ruby file but without an extension). I'm facing the same issue with large shell utilities whose library files don't tend to carry an extension. It's a huge drag to have to manually select the correct language each time I open a file...especially when you are working on a project with dozens of extension-less files. Sublime Text, for example, has a couple of plugins that implement this functionality (reading the first X number of lines of a file in search of a modeline, if it exists select the language from the modeline, otherwise try and use the file extension, otherwise fall back to plain text). The OP (@ctlajoie) created such a plugin for vscode but is unable to implement language selection because of the lack of support by the vscode API. |
Any update on this issue ? |
writing my first extension and have spent the past 12 hours trying to figure out a work around for this. Need this ability desperately.., I don't want to use the previewHtml. created a textdocumentcontentprovider, the contents of which are JSON and I'd like to set the languageId to json so the user doesn't have to do it manually.. |
I need this as well for some extensions I'm working with |
I'd like this to work with Example
Thanks for reading! |
This could be a solution to #670 for php. Could hook into the selection changed event when in and out of php tags to automatically toggle active language. |
Would love to see this added either as an arg we can pass or as a separate command. |
Is there a way to get an extension id from a filename string, say |
@alexandrudima Thinking about the API for this and I wonder why we decided that changing a mode is expressed as a close/open-event-sequence. See https://github.com/Microsoft/vscode/blob/a69c03e4ca08f58b67ed4b91eaa57e2db44592e6/src/vs/workbench/api/node/extHostDocuments.ts#L103 |
Ok, one advantage of sending a close/open-sequence is that validation participants have an easy way to 'follow' documents of a certain language |
Current finalisation proposal /**
* Set (and change) the [language](#TextDocument.languageId) that is associated
* with the given document.
*
* *Note* that calling this function will trigger the [`onDidCloseTextDocument`](#languages.onDidCloseTextDocument) event
* followed by the [`onDidOpenTextDocument`](#languages.onDidOpenTextDocument) event.
*
* @param document The document which language is to be changed
* @param languageId The new language identifier.
* @returns A thenable that resolves with the updated document.
*/
export function setTextDocumentLanguage(document: TextDocument, languageId: string): Thenable<TextDocument>; |
This is API now |
How do you use this? is there documentation for it? |
@bbrendon you can take a look at "Rainbow CSV" or "vscode-modelines" source code for usage examples. |
I have a modelines plugin but it currently lacks the ability to set the language of the file. In order to implement this I would need an API to allow it to be set.
As an example, a Vagrantfile is a ruby script, but Code opens it as plain text. The API should allow plugins to determine the type of file by arbitrary means and set the language appropriately.
The text was updated successfully, but these errors were encountered: