Skip to content

fix: avoid writing default autoSelectOrganization to workspace config [IDE-1738]#715

Open
bastiandoetsch wants to merge 2 commits intomainfrom
fix/IDE-1738_only-write-folder-config-if-needed
Open

fix: avoid writing default autoSelectOrganization to workspace config [IDE-1738]#715
bastiandoetsch wants to merge 2 commits intomainfrom
fix/IDE-1738_only-write-folder-config-if-needed

Conversation

@bastiandoetsch
Copy link
Copy Markdown
Contributor

@bastiandoetsch bastiandoetsch commented Feb 6, 2026

User description

Description

Fixes user-reported issue where the snyk.advanced.autoSelectOrganization setting was always written into the workspace configuration file (.vscode/settings.json), even when the value was true (the default). This polluted workspace configs unnecessarily and was unwanted by users.

Root cause: In handleOrgSettingsFromFolderConfigs, the condition desiredAutoOrg !== currentAutoOrg || desiredAutoOrg always evaluated to true when desiredAutoOrg was true (the common default case where the user hasn't manually set an org).

Fix:

  • Changed the condition to desiredAutoOrg !== currentAutoOrg — only write when there's an actual change
  • When clearing a folder-level override back to default, write undefined instead of true to remove the setting entirely from workspace config
  • Updated setAutoSelectOrganization to accept boolean | undefined

Checklist

Screenshots / GIFs

N/A — no UI changes.


PR Type

Bug fix


Description

  • Avoid writing default auto-select-organization to workspace config.

  • Only write folder config if value differs from effective config.

  • Clear folder-level override when falling back to default.


Diagram Walkthrough

flowchart LR
  A[Old Logic: Always Write Default] --> B{Check If Desired Matches Current};
  B -- True --> C[Write Value];
  B -- False --> D[Skip Write];
  E[New Logic: Write Only if Different] --> F{Desired != Current?};
  F -- True --> G{Is Desired True?};
  G -- True --> H[Write Undefined (Clear Override)];
  G -- False --> I[Write False];
  F -- False --> D;
Loading

File Walkthrough

Relevant files
Bug fix
configuration.ts
Update setAutoSelectOrganization signature                             

src/snyk/common/configuration/configuration.ts

  • Modified setAutoSelectOrganization to accept boolean | undefined.
  • Updated the method signature to reflect the new parameter type.
+9/-3     
languageServer.ts
Refine auto-organization setting logic                                     

src/snyk/common/languageServer/languageServer.ts

  • Changed logic to only write autoSelectOrganization if the desired
    value differs from the current effective value.
  • When clearing a folder-level override back to default, it now writes
    undefined instead of true.
  • Updated log messages to reflect the new behavior.
+7/-5     
Tests
languageServer.test.ts
Update language server tests for auto-org settings             

src/test/unit/common/languageServer/languageServer.test.ts

  • Added a test case to verify that autoSelectOrganization is not written
    when orgSetByUser is false and currentAutoOrg is already true.
  • Added a test case to verify that the folder-level
    autoSelectOrganization override is cleared by writing undefined when
    orgSetByUser is false and currentAutoOrg is false.
+31/-16 

… [IDE-1738]

The autoSelectOrganization setting was always written to the workspace
folder configuration (.vscode/settings.json), even when the value was
true (the default). This polluted workspace configs unnecessarily.

Root cause: the condition `desiredAutoOrg !== currentAutoOrg || desiredAutoOrg`
always evaluated to true when desiredAutoOrg was true (the default case).

Fix: only write when the desired value actually differs from the current
effective value. When clearing a folder-level override back to default,
write undefined instead of true to remove the setting entirely.

Co-authored-by: Cursor <cursoragent@cursor.com>
@bastiandoetsch
Copy link
Copy Markdown
Contributor Author

/describe

@snyk-io
Copy link
Copy Markdown

snyk-io bot commented Feb 6, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@snyk-pr-review-bot
Copy link
Copy Markdown

PR Description updated to latest commit (b9f821d)

@bastiandoetsch bastiandoetsch marked this pull request as ready for review February 6, 2026 08:49
@bastiandoetsch bastiandoetsch requested review from a team as code owners February 6, 2026 08:49
@snyk-pr-review-bot

This comment has been minimized.

@snyk-pr-review-bot
Copy link
Copy Markdown

PR Reviewer Guide 🔍

🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Type Definition

The JSDoc for autoSelectOrganization on line 173 mentions "or undefined to clear the folder-level override", which aligns with the code changes. However, the type for the parameter autoSelectOrganization in the IConfiguration interface (line 177) and the Configuration class implementation (line 626) is boolean | undefined. It would be clearer to explicitly state that undefined clears the setting, rather than just saying "or undefined" in the description, or just mention the updated type boolean | undefined. This is a minor point as the code itself correctly handles it.

 * @param autoSelectOrganization - Whether auto organization should be enabled, or undefined to clear the folder-level override
 */
setAutoSelectOrganization(
  workspaceFolder: WorkspaceFolder,
  autoSelectOrganization: boolean | undefined,
Magic Value

The use of undefined (line 367) as a special value to clear a setting is a pattern that can sometimes lead to confusion if not clearly documented or consistently applied. While the JSDoc and PR description explain its purpose here, consider if a more explicit constant or utility function could encapsulate this meaning, especially if this pattern is to be reused. However, given this.workspace.updateConfiguration likely treats undefined as "unset", this might be a standard VS Code extension practice.

const valueToWrite = desiredAutoOrg ? undefined : false;
📚 Repository Context Analyzed

This review considered 11 relevant code sections from 10 files (average relevance: 0.91)

Copy link
Copy Markdown
Contributor

@michelkaporin michelkaporin left a comment

Choose a reason for hiding this comment

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

I'll leave the code review to your team - we're aligned on the behavioural implementation, thank you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants