Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

250
Visualizações
Update user/workspace settings from vs code extension

I am trying to update setting.json from my vs code extension and I want to add below code

 "files.associations": {
        "*.app": "auraComponent"
    }

In other words I want to add below key value pair from extension to the users who are going to install my app

enter image description here

So I tried putting the below code in extension.js but it didn't update the settings.

import { ConfigurationTarget, workspace } from 'vscode';

const configuration = workspace.getConfiguration('files.associations');
configuration.update('.app', 'auraComponent', ConfigurationTarget.Global).then(() => {
    // take action here
});

Could someone please suggest if I am using the right approach to update the user or workspace settings and also if the code inside extension.js would be executed automatically or not.

Update

I have added extension.js and included the js code as mentioned by mark in his answer

and update my package.json as below

"main": "./extension",
"activationEvents": [
    "*"
],

If I run my extension on debug mode then it works fine but not working in real time.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The below works whether there is a pre-existing files.association setting or not. If there is already one, the new association is added to it (and so may be located somewhere other than the end of the settings file - otherwise a wholly new files.associations setting will be added to the very end of the settings.json file..

const fileConfiguration = vscode.workspace.getConfiguration('files');
const associations = fileConfiguration.get('associations');

associations['*.app'] = "auraComponent";

fileConfiguration.update('associations', associations, vscode.ConfigurationTarget.Global).then(() => {

    // take action here
});

Adapted from https://stackoverflow.com/a/49566662/836330.

As explained there, what you really want to update is the associations object, that is the value to be updated. "*.app": "auraComponent is not a configuration key. files.associations is the key and there is an object {...} which is its value.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda