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

Trigger language auto detection mechanism #11838

Open
XVincentX opened this issue Sep 11, 2016 · 12 comments
Open

Trigger language auto detection mechanism #11838

XVincentX opened this issue Sep 11, 2016 · 12 comments
Assignees
Labels
api feature-request Request for new features or functionality languages-basic Basic language support issues
Milestone

Comments

@XVincentX
Copy link
Member

Some times I'm fetching some content from the web and pasting it into the current active editor.
So far, I didn't find any way to set the current language for the window. Is there any particular API call for that?

Even better, would it be possible to trigger the auto detection mechanism with the API?

@ramya-rao-a
Copy link
Contributor

See Changing language for current file

Please ask 'how-to' questions about VS Code on Stack Overflow using the tag vscode.
The VS Code development team together with the VS Code Community will answer question your question over there.
Here is how the development team tracks feedback on the different channels: Feedback Channels.

@XVincentX
Copy link
Member Author

XVincentX commented Sep 11, 2016

@ramya-rao-a ??????
Hmm...I am not talking the IDE itself, I'm talking from an extension context. I'm missing an API function to make that happen. Does that clarify?

@XVincentX
Copy link
Member Author

My point is that - it seems that TextEditor class is missing methods to set current language type, or eventually trigger the auto detect mechanism

@ramya-rao-a
Copy link
Contributor

Sorry, I thought you were talking from a user's perspective rather than an extension author. Will look into it and get back to you

@ramya-rao-a ramya-rao-a reopened this Sep 11, 2016
@jrieken jrieken added the feature-request Request for new features or functionality label Sep 12, 2016
@jrieken
Copy link
Member

jrieken commented Sep 12, 2016

@XVincentX This mostly depends on the filename and 'pasting it into the editor' will miss that information I guess.

@XVincentX
Copy link
Member Author

@jrieken
Is there any plan to provide an API call to trigger the auto detection?
In my use cases, giving I'm providing regexp in languages I support, it would really solve my problem here.

Thanks!

@XVincentX
Copy link
Member Author

@jrieken I started contributing #12035 and I liked it.

Would you be open to an user contribution here?
If you could point out where I should start look, I'd love to give it a try!

@mbana
Copy link

mbana commented Dec 5, 2017

Hi,

I am faced with a similar problem/scenario as the original poster. Let's say you're faced with this scenario:

  1. Open new a editor.
  2. Paste in some content, say, it's JSON.
  3. I want the VSCode to auto-detect that it is JSON only and set the langauge accordingly.

Is it this possible, or is it at least something in the pipeline?

From an implementation point of view, I would do:

  1. Loop through all the languages.
  2. Paste content there and see if it's a match.
  3. If match is found, set that as the language.

This is quite crude, but I hope that gets the point across.


Regardless +1 for this feature.

@zlzdp

This comment was marked as spam.

@jrieken jrieken added this to the Backlog milestone Oct 31, 2019
@jrieken jrieken added the languages-basic Basic language support issues label Nov 9, 2020
@JonasKru

This comment was marked as spam.

@gjsjohnmurray
Copy link
Contributor

@jrieken is the idea to provide new API vscode.languages.detectLanguage(resource: Uri, supportedLanguageIds?: string[]): Thenable<string | undefined> which would get wired through to the detectLanguage method of LanguageDetectionService?

async detectLanguage(resource: URI, supportedLangs?: string[]): Promise<string | undefined> {
const useHistory = this._configurationService.getValue<string[]>(LanguageDetectionService.historyBasedEnablementConfig);
const preferHistory = this._configurationService.getValue<boolean>(LanguageDetectionService.preferHistoryConfig);
if (useHistory) {
await this.resolveWorkspaceLanguageIds();
}
const biases = useHistory ? this.getLanguageBiases() : undefined;
return this._languageDetectionWorkerClient.detectLanguage(resource, biases, preferHistory, supportedLangs);
}

@mikeburgh
Copy link

Adding that new API would be great!

I found you can also call vscode.commands.executeCommand('editor.detectLanguage') which will run the detection on the active editor.. but it's not silent, and if it does not find a match a warning notification is displayed. Would it be easier to add a silent option to that command ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api feature-request Request for new features or functionality languages-basic Basic language support issues
Projects
None yet
Development

No branches or pull requests

8 participants