Skip to content

Add setting to disable automatic YAML file association #1026

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

Conversation

scrthq
Copy link

@scrthq scrthq commented Feb 25, 2021

Should resolve #961 without changing existing default behavior.

Changes:

  • Add boolean setting vscode-home-assistant.disableAutomaticFileAssociation (defaults to false).
  • Update HomeAssistantConfiguration interface and ConfigurationService class with the disableAutomaticFileAssociation property (not currently used, but keeping LS configuration in sync with available configuration options).
  • Update to fileAssociations section of extension.ts with an additional conditional check in the if statement to read in the new configuration setting.

@frenck
Copy link
Collaborator

frenck commented Feb 26, 2021

While this is a nice option, we should improve the detection on when to enable it... This feels more like a workaround for the problem.

@frenck frenck changed the title (add) setting to disable automatic yaml file association Add setting to disable automatic yaml file association Feb 26, 2021
@frenck frenck changed the title Add setting to disable automatic yaml file association Add setting to disable automatic YAML file association Feb 26, 2021
@frenck frenck added the enhancement New feature or request label Feb 26, 2021
@scrthq
Copy link
Author

scrthq commented Feb 26, 2021

@frenck - Agreed that this is a workaround and better detection would be great, but I still feel like there should be an option to disable it entirely (ideally default to that behavior being disabled and allow opt-in instead of opt-out). I can't think of any other extension that modifies workspace settings like this, especially creating files when they might not already exist purely for the sake of convenience. Shouldn't need to keep the extension globally disabled and enable per workspace simply to avoid unexpected behavior.

Detection is nice and all, but configuration.yaml isn't exactly a naming convention that's specific to Home Assistant and there aren't really other required files to maintain in a Home Assistant focused workspace, especially when using add-ons like the Git Pull add-on where you don't have every Home Assistant file in your Home Assistant Code workspace.

If there's something that you're thinking of that would be a step in a better direction, I'd be happy to modify my PR with the recommended changes.

@frenck
Copy link
Collaborator

frenck commented Feb 26, 2021

Detection is nice and all, but configuration.yaml isn't exactly a naming convention that's specific to Home Assistant and there aren't really other required files to maintain in a Home Assistant focused workspace, especially when using add-ons like the Git Pull add-on where you don't have every Home Assistant file in your Home Assistant Code workspace.

I don't agree with that, as it is pretty unique to be configuration.yaml that contains a homeassistant key.

@scrthq
Copy link
Author

scrthq commented Feb 26, 2021

That's fair if we're parsing the YAML file to check the contents as well! Right now excluding my additions, the fileAssociations section appears to only check if the workspace settings file does not contain a key of *.yaml and does not contain a value of home-assistant before it updates/creates the workspace settings file. I'm not seeing anything that actually looks at content or even looks for a configuration.yaml file in the workspace.

There are bits on haConfig.ts and haYamlFile.ts that do some parsing, but those aren't referenced in the extension.ts segment that manages the actual settings fileAssociations.

@scrthq
Copy link
Author

scrthq commented Feb 26, 2021

From what I can tell, it looks like the extension is activated for file presence of configuration.yaml or ui-lovelace.yaml and the extension client activation checks the settings file and updates it based on the contents of the settings, not the contents of the configuration.yaml file.

@frenck
Copy link
Collaborator

frenck commented Feb 26, 2021

That is correct, I was referring to the fact that it should be improved, not worked around.

@scrthq
Copy link
Author

scrthq commented Feb 26, 2021

Checking that out! I'm not a TS/JS developer typically, so this should be fun 😄

@scrthq
Copy link
Author

scrthq commented Feb 26, 2021

@frenck -- curious if you have some rough implementation guidance here. Seeing your parseAstRecursive function in language-server/src/haConfig/haYamlFile.ts which appears to be useful here (at least a subset of it). I'd like to avoid repeating code between the extension.ts and the language server code, but I'm not sure offhand if that's doable based on how the current file/function structure does not appear to show any shared code between the two. I think some sort of common module might be good here, but we obviously don't need the full AST just to check if configuration.yaml/homeassistant path exists. Fallback option would be to define a single purpose function/check directly on extension.ts, but trying to avoid that becoming too bulky if possible.

@frenck
Copy link
Collaborator

frenck commented Mar 4, 2021

I honestly think this is more up into @keesschollaart81 his alley

@Nicholaiii
Copy link
Contributor

You can disable/enable extensions per workspace, so there's really no need for a boolean setting, however nice it may be. You can globally disable vsc-ha and enable it only in your HA workspace
image

@frenck frenck requested a review from Copilot May 14, 2025 20:08
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds an option to disable the automatic YAML file association for the Home Assistant language without altering the default behavior.

  • Introduces the disableAutomaticFileAssociation setting in the configuration interface and service.
  • Updates the extension activation logic to skip file association when the setting is enabled.
  • Extends the package schema to include the new boolean setting.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/language-service/src/configuration.ts Added disableAutomaticFileAssociation to interface and class
src/extension.ts Added conditional check for the new setting in file association logic
package.json Defined the new setting in the extension’s configuration schema
Comments suppressed due to low confidence (4)

src/extension.ts:335

  • [nitpick] Consider scoping your configuration lookup to your extension's namespace by calling getConfiguration('vscode-home-assistant') and then .get('disableAutomaticFileAssociation', false) for clarity and consistency.
vscode.workspace.getConfiguration()

src/extension.ts:331

  • Add a unit or integration test to cover the automatic file association logic when disableAutomaticFileAssociation is both true and false, ensuring both paths behave as expected.
if (

package.json:58

  • [nitpick] The indentation for this new setting is slightly misaligned compared to the surrounding properties—align it to improve readability.
"vscode-home-assistant.disableAutomaticFileAssociation": {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The VSCode settings.json file is getting created on non-HA repos
3 participants