Skip to content

#163967 css alias - #460

Open
Simon Stranks (SStranks) wants to merge 19 commits into
microsoft:mainfrom
SStranks:#163967-css-alias
Open

Simon Stranks (SStranks) wants to merge 19 commits into
microsoft:mainfrom
SStranks:#163967-css-alias

Conversation

@SStranks

@SStranks Simon Stranks (SStranks) commented Oct 14, 2025 •

Copy link
Copy Markdown
Contributor

In conjunction with Pull Request #197033 on the vscode repository.

I reworked the previous merged code for this feature so that it now handles single-root, multi-root, and mono-repo project structures.

To clarify, aliases for css/scss are specified in the .vscode/settings.json under 'importAliases' for each language as before - I have updated the tool-tip descriptions in the package.nls.json file, and made code changes to cssServer to accommodate the functionality in the current PR - see PR 197033 above.

Functionality

  • Settings files/aliases at the workspace root take priority over any nested settings files. This allows avoiding directory tree lookup for settings files if a valid alias is discovered there first.
  • If no settings/alias is found at the workspace root; attempt lookup for .vscode/settings.json from document towards workspace root.
  • If lookup finds settings file; cache the path and cache the aliases for that document to avoid repeat lookups.
  • Added Public clearCache() method to CSSNavigation; to be called when settings.json changes (see limitations section below)

Changes

  • Added functionality above.
  • Updated: navigation tests.
  • Added: test fixture files

Limitations

  • clearCache() method only fires when settings files tracked by vscode are changed. Settings files discovered by lookup in cssNavigation are not covered. I didn't see a straightforward way to implement this; vscode cssServer imports connection.onDidChangeConfiguration from vscode-languageserver, and handles the watcher. Willing to make further changes if someone can suggest how/where to look.

Comment thread src/services/cssNavigation.ts Outdated
} from '../languageFacts/facts.js';
import { startsWith } from '../utils/strings.js';
import { dirname, joinPath } from '../utils/resources.js';
import { readFile } from 'node:fs/promises';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We must not use nodejs functionality as the code can also run in the browser.

To read files use the fileSystemProvider

@aeschli

Copy link
Copy Markdown
Collaborator

Finding and loading settings should not be part of the vscode-css-languageservice. That should be done outside, by the client of the service.
vscode-css-languageservice should just get the AliasSettings

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Finding and loading settings should not be part of the vscode-css-languageservice. That should be done outside, by the client of the service.
vscode-css-languageservice should just get the AliasSettings

Comment thread src/services/cssNavigation.ts Outdated
const json = JSON.parse(text);
return json;
} catch (error) {
console.warn(`Failed to read ${candidate}:`, error);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

remove console statement

const root = URI.parse(workspaceFolder);
let current = document;

while (current.path.startsWith(root.path)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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