Skip to content

Commit

Permalink
fix: setting for css completions in Sass, SCSS
Browse files Browse the repository at this point in the history
  • Loading branch information
wkillerud committed Sep 25, 2024
1 parent 6c24f34 commit 35da87b
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 11 deletions.
2 changes: 2 additions & 0 deletions docs/src/user-guide/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ Open your user settings JSON and paste this configuration. You may want to resta
"somesass.scss.colors.enabled": true,
"somesass.scss.colors.includeFromCurrentDocument": true,
"somesass.scss.completion.enabled": true,
"somesass.scss.completion.css": true,
"somesass.scss.completion.includeFromCurrentDocument": true,
"somesass.scss.definition.enabled": true,
"somesass.scss.diagnostics.enabled": true,
"somesass.scss.diagnostics.lint.enabled": true,
"somesass.scss.foldingRanges.enabled": true,
"somesass.scss.highlights.enabled": true,
"somesass.scss.hover.enabled": true,
"somesass.scss.hover.documentation": true,
"somesass.scss.links.enabled": true,
"somesass.scss.references.enabled": true,
"somesass.scss.rename.enabled": true,
Expand Down
1 change: 1 addition & 0 deletions packages/language-server/rspack.node.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const config = {
syntax: "typescript",
},
externalHelpers: true,
target: "es2022",
},
},
},
Expand Down
3 changes: 3 additions & 0 deletions packages/language-services/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const defaultConfiguration: LanguageServerConfiguration = {
},
completion: {
enabled: true,
css: true,
includeFromCurrentDocument: true,
completePropertyWithSemicolon: true,
triggerPropertyValueCompletion: true,
Expand Down Expand Up @@ -98,6 +99,7 @@ export const defaultConfiguration: LanguageServerConfiguration = {
},
completion: {
enabled: true,
css: true,
mixinStyle: "all",
includeFromCurrentDocument: true,
suggestFromUseOnly: false,
Expand Down Expand Up @@ -178,6 +180,7 @@ export const defaultConfiguration: LanguageServerConfiguration = {
},
completion: {
enabled: true,
css: true,
mixinStyle: "all",
includeFromCurrentDocument: true,
suggestFromUseOnly: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ beforeEach(() => {
scss: {
completion: {
suggestFromUseOnly: true,
css: false,
},
},
sass: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ const ls = getLanguageService({ fileSystemProvider, ...rest });
ls.configure({
scss: {
completion: {
suggestAllFromOpenDocument: true,
includeFromCurrentDocument: true,
suggestFromUseOnly: false,
css: false,
},
},
});
Expand Down
10 changes: 5 additions & 5 deletions packages/language-services/src/features/do-complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,15 @@ export class DoComplete extends LanguageFeature {
}
}

if (document.languageId === "sass") {
const upstreamResult = await upstreamLs.doComplete2(
if (config.completion.css) {
const cssResults = await upstreamLs.doComplete2(
document,
position,
stylesheet,
this.getDocumentContext(),
);
if (upstreamResult.items.length > 0) {
result.items.push(...upstreamResult.items);
if (cssResults.items.length > 0) {
result.items.push(...cssResults.items);
}
}

Expand Down Expand Up @@ -520,7 +520,7 @@ export class DoComplete extends LanguageFeature {
const items: CompletionItem[] = [];
const result = await this.findInWorkspace<CompletionItem>((document) => {
// keep track of visited to avoid duplicates
// if completionSettings?.suggestFromUseOnly is false
// if suggestFromUseOnly is false
visited.add(document.uri);

const symbols = this.ls.findDocumentSymbols(document);
Expand Down
6 changes: 3 additions & 3 deletions packages/language-services/src/features/do-hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ export class DoHover extends LanguageFeature {
type = SymbolKind.Method;
}
if (type === null) {
if (document.languageId === "sass") {
// We are probably hovering over a CSS identifier
// and want to defer this to vscode-css-languageservice's hover handler
if (config.hover.documentation) {
// We are probably hovering over a CSS identifier.
// In VS Code, by default we defer this to vscode-css-languageservice's hover handler.
return this.getUpstreamLanguageServer(document).doHover(
document,
position,
Expand Down
4 changes: 4 additions & 0 deletions packages/language-services/src/language-services-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ export interface LanguageConfiguration {
};
completion: {
enabled: boolean;
/**
* Include CSS completions.
*/
css?: boolean;
/**
* Mixins with `@content` SassDoc annotations and `%placeholders` get two suggestions by default:
* - One without `{ }`.
Expand Down
18 changes: 16 additions & 2 deletions vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@
"Where brackets are suggested, don't suggest without brackets"
]
},
"somesass.scss.completion.css": {
"order": 33,
"type": "boolean",
"scope": "resource",
"default": false,
"description": "Compatibility setting for VS Code. Enable or disable CSS completions (IntelliSense). The built-in SCSS language server provides this, so by default it's turned off in Some Sass."
},
"somesass.scss.completion.triggerPropertyValueCompletion": {
"order": 33,
"type": "boolean",
Expand Down Expand Up @@ -488,15 +495,15 @@
"order": 81,
"type": "boolean",
"scope": "resource",
"default": true,
"default": false,
"description": "Show property and value documentation in CSS hovers."
},
"somesass.scss.hover.references": {
"order": 82,
"type": "boolean",
"scope": "resource",
"default": true,
"description": "Show references to MDN in CSS hovers, Sass documentation for Sass built-in modules and SassDoc for annotations."
"description": "Show references to Sass documentation for Sass built-in modules and SassDoc for annotations."
},
"somesass.scss.links.enabled": {
"order": 90,
Expand Down Expand Up @@ -593,6 +600,13 @@
"Where brackets are suggested, omit duplicates without brackets"
]
},
"somesass.sass.completion.css": {
"order": 33,
"type": "boolean",
"scope": "resource",
"default": true,
"description": "Enable or disable CSS completions (IntelliSense)."
},
"somesass.sass.completion.triggerPropertyValueCompletion": {
"order": 33,
"type": "boolean",
Expand Down

0 comments on commit 35da87b

Please sign in to comment.