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

Allow extensions to get a LanguageConfiguration for a language #2871

Closed
stkb opened this issue Feb 9, 2016 · 11 comments
Closed

Allow extensions to get a LanguageConfiguration for a language #2871

stkb opened this issue Feb 9, 2016 · 11 comments
Assignees
Labels
api *duplicate Issue identified as a duplicate of another issue(s) feature-request Request for new features or functionality languages-basic Basic language support issues
Milestone

Comments

@stkb
Copy link
Contributor

stkb commented Feb 9, 2016

As far as I can tell, extensions can set a LanguageConfiguration object for a language with languages.setLanguageConfiguration(), but they can't get an existing one. This would be very useful for getting information about the language of the current document.

@alexdima
Copy link
Member

fyi @jrieken

@wiggin77
Copy link

I need this as well. I am writing an extension that enhances other language extensions and need to look up things like what autoclosing pairs are defined.

@dinhani
Copy link

dinhani commented Jan 24, 2017

I also need this to retrieve information about the comments for the current language.

@SuyogSoti
Copy link

A little hack that I have done is

    var ext;
    if(fs.existsSync("/usr/share/code/resources/app/extensions")){
        ext = fs.readFileSync("/usr/share/code/resources/app/extensions/" + editor.document.languageId + "/" + "language-configuration.json", "utf8");
    }else{
        ext = fs.readFileSync("C:///Program Files (x86)/Microsoft VS Code/resources/app/extensions" + editor.document.languageId + "/" + "language-configuration.json", "utf8");
    }

This little hack seems to work for all of the default languages for vscode. I would however love to have api to have access to this.

@IMFUZZ
Copy link

IMFUZZ commented Oct 21, 2017

I know it's been some time, but I have encountered the same problem. Fetching the "language-configuration.json" file using the "languageId" is not reliable since some languages uses "-language-configuration.json" ("javascript" for example) or the folder of the extension itself does not correspond to the languageId ("dockerfile" being inside the "docker" extension folder for example).

Anybody found a good work-around?

@IMFUZZ
Copy link

IMFUZZ commented Oct 21, 2017

ok, I found a pretty good way:

const editor = vscode.window.activeTextEditor;
const documentLanguageId:string = editor.document.languageId;
var langConfigFilepath:string = null;
for (const _ext of vscode.extensions.all) {
  // All vscode default extensions ids starts with "vscode."
  if (
    _ext.id.startsWith("vscode.") &&
    _ext.packageJSON.contributes &&
    _ext.packageJSON.contributes.languages
  ) {
    // Find language data from "packageJSON.contributes.languages" for the languageId
    const packageLangData = _ext.packageJSON.contributes.languages.find(
      _packageLangData => (_packageLangData.id === documentLanguageId)
    );
    // If found, get the absolute config file path
    if (!!packageLangData) {
      langConfigFilepath = path.join(
        _ext.extensionPath,
        packageLangData.configuration
      );
      break;
    }
  }
}
// Validate config file existance
if (!!langConfigFilepath && fs.existsSync(langConfigFilepath)) {
  langConfig = require(langConfigFilepath);
  // PROFIT
}

Note: I would recommend that you use an external node module that parses json containing comments (comment-json for example) instead of require(...), since some of vscode's language-configuration have some. Making them invalid JSON which breaks require() and JSON.parse.

@davidquinn
Copy link

I was wondering if there is any plan to resolve this (expose the current document's language configuration)? I don't like the workarounds above which are clever, but hacky and not guaranteed to work.

I am the author of the psioniq File Header extension, and at the moment, the only way to define the comment start/end/prefix is to include it in my extension's configuration. This requires users to unnecessarily duplicate configuration settings that are already (and more safely) part of the language config.

@vscodebot
Copy link

vscodebot bot commented Jan 15, 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!

@vscodebot
Copy link

vscodebot bot commented Jan 31, 2020

🙂 This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@dbaeumer
Copy link
Member

I would also need this for ESLint.

@alexr00
Copy link
Member

alexr00 commented Nov 10, 2021

Duplicate of #109919

@alexr00 alexr00 marked this as a duplicate of #109919 Nov 10, 2021
@alexr00 alexr00 closed this as completed Nov 10, 2021
@alexr00 alexr00 added the *duplicate Issue identified as a duplicate of another issue(s) label Nov 10, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Dec 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api *duplicate Issue identified as a duplicate of another issue(s) feature-request Request for new features or functionality languages-basic Basic language support issues
Projects
None yet
Development

No branches or pull requests

10 participants