Skip to content

Commit

Permalink
fix: apply completion settings
Browse files Browse the repository at this point in the history
Somehow this fell through the cracks. E2E tests only use the default
settings, and tests at the lower levels didn't catch the missing
link in the server.
  • Loading branch information
wkillerud committed Aug 20, 2024
1 parent 68f7e1f commit a8cf761
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ export class SomeSassServer {
editorSettings,
workspaceRoot,
loadPaths: settings.loadPaths,
completionSettings: {
...settings,
},
});

workspaceScanner = new WorkspaceScanner(ls, fileSystemProvider, {
Expand Down Expand Up @@ -218,9 +221,17 @@ export class SomeSassServer {
this.connection.onDidChangeConfiguration((params) => {
if (!ls) return;

const somesassConfiguration: Partial<ISettings> =
params.settings.somesass;

const editorConfiguration: Partial<IEditorSettings> =
params.settings.editor;

const settings: ISettings = {
...defaultSettings,
...somesassConfiguration,
};

const editorSettings: IEditorSettings = {
insertSpaces: false,
indentSize: undefined,
Expand All @@ -231,6 +242,9 @@ export class SomeSassServer {
ls.configure({
editorSettings,
workspaceRoot,
completionSettings: {
...settings,
},
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { test, assert, beforeEach } from "vitest";
import { getLanguageService } from "../../language-services";
import { Position } from "../../language-services-types";
import { getOptions } from "../../utils/test-helpers";

const { fileSystemProvider, ...rest } = getOptions();
const ls = getLanguageService({ fileSystemProvider, ...rest });

beforeEach(() => {
ls.clearCache();
ls.configure({
completionSettings: {
suggestFromUseOnly: true,
},
}); // Reset any configuration to default
});

test("symbols forwarded from node_modules don't get suggested unless used", async () => {
const pkg = fileSystemProvider.createDocument(['{ "name": "test-module" }'], {

Check warning on line 19 in packages/language-services/src/features/__tests__/do-complete-node-modules.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

'pkg' is assigned a value but never used

Check warning on line 19 in packages/language-services/src/features/__tests__/do-complete-node-modules.test.ts

View workflow job for this annotation

GitHub Actions / test (macos-13)

'pkg' is assigned a value but never used

Check warning on line 19 in packages/language-services/src/features/__tests__/do-complete-node-modules.test.ts

View workflow job for this annotation

GitHub Actions / test (windows-latest)

'pkg' is assigned a value but never used
languageId: "json",
uri: "node_modules/sass-true/package.json",
});
const module = fileSystemProvider.createDocument(
["$catch-errors: false !default;"],
{
uri: "node_modules/sass-true/_throw.scss",
},
);
const forward = fileSystemProvider.createDocument(['@forward "sass-true";'], {
uri: "_test.scss",
});
const unrelated = fileSystemProvider.createDocument(["@debug $"]);

ls.parseStylesheet(module);
ls.parseStylesheet(forward);
ls.parseStylesheet(unrelated);

const { items } = await ls.doComplete(unrelated, Position.create(0, 8));
assert.notOk(
items.find((item) => item.label === "$catch-errors"),
"Expected not to find $catch-errors in suggestions",
);
});

0 comments on commit a8cf761

Please sign in to comment.