Skip to content

Commit 07953dc

Browse files
authored
feat: add {module} as a magic string for the afterModule setting (#229)
This should fix an issue seen in SublimeText where the editor would replace the module itself (eg module.$variable, module would disappear).
1 parent d7523d3 commit 07953dc

File tree

7 files changed

+89
-7
lines changed

7 files changed

+89
-7
lines changed

.vscode/launch.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
{
33
"version": "0.2.0",
44
"configurations": [
5+
{
6+
"name": "Attach to language server running with --inspect",
7+
"port": 9229,
8+
"request": "attach",
9+
"skipFiles": [
10+
"<node_internals>/**"
11+
],
12+
"type": "node"
13+
},
514
{
615
"type": "extensionHost",
716
"request": "launch",

docs/src/contributing/debugging.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,27 @@ Find `browser-server.js` in the `vscode-extension/dist/` folder to set breakpoin
4242

4343
Restart the debugger after building to see any changes you make in the code.
4444

45+
## Attach to a running language server
46+
47+
If you need to debug an interaction in an editor other than Visual Studio Code,
48+
you can run the language server using Node [with the `--inspect` flag](https://nodejs.org/en/learn/getting-started/debugging).
49+
50+
For example, in Sublime Text, this should be the command:
51+
52+
```json
53+
{
54+
"command": ["${node_bin}", "--inspect", "${server_path}", "--stdio", "--debug"]
55+
}
56+
```
57+
58+
Note that we also use the `--debug` flag in order to run the language server's non-minified bundle.
59+
60+
You can then [attach an inspector client](https://nodejs.org/en/learn/getting-started/debugging#inspector-clients).
61+
62+
In VS Code, once the debugger is attached, you should be able to find the language server's script in the Loaded scripts section.
63+
There you can place breakpoints to step through the code you want to inspect.
64+
65+
![](../images/debugging/attach-to-server.png)
66+
4567
[exthost]: https://code.visualstudio.com/api/advanced-topics/extension-host
4668
[vsdebug]: https://code.visualstudio.com/docs/editor/debugging
315 KB
Loading

docs/src/language-server/configure-a-client.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,24 @@ For example, while we may document `"somesass.loadPaths": []` (and write it this
2828

2929
In addition to [the user settings](../user-guide/settings.md), language clients may want to configure these server-only settings to tweak how certain features interact with your specific editor.
3030

31-
| Key | Description |
32-
| ------------------------------------ | ----------------------------------------------------------------------------------------------------------- |
33-
| `somesass.completion.afterModule` | Set this to the empty string if you end up with `module..$variable` after accepting a code suggestion item. |
34-
| `somesass.completion.beforeVariable` | Set this to the empty string if you end up with `$$variable` after accepting a code suggestion item. |
31+
| Key | Description |
32+
| ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
33+
| `somesass.completion.afterModule` | Set this to the empty string if you end up with `module..$variable` after accepting a code suggestion item. If `module.` or `module` disappears, you can set it to `"{module}."` or `"{module}"` respectively. That is a "magic string" that will be replaced with the actual module name. |
34+
| `somesass.completion.beforeVariable` | Set this to the empty string if you end up with `$$variable` after accepting a code suggestion item. |
35+
36+
For example:
37+
38+
```json
39+
{
40+
"settings": {
41+
"somesass": {
42+
"completion": {
43+
"afterModule": "{module}"
44+
}
45+
}
46+
}
47+
}
48+
```
3549

3650
## Existing clients
3751

packages/language-services/src/features/do-complete.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,13 @@ export class DoComplete extends LanguageFeature {
861861
? asDollarlessVariable(label)
862862
: label;
863863

864+
if (
865+
this.configuration.completionSettings?.afterModule &&
866+
this.configuration.completionSettings.afterModule.startsWith("{module}")
867+
) {
868+
insertText = `${namespace}${insertText}`;
869+
}
870+
864871
filterText = currentWord.endsWith(".") ? `${namespace}.${label}` : label;
865872
} else if (
866873
dotExt === ".vue" ||
@@ -926,12 +933,21 @@ export class DoComplete extends LanguageFeature {
926933
initialDocument.languageId === "sass" ||
927934
this.configuration.completionSettings?.afterModule === "";
928935

929-
const insertText = namespace
936+
let insertText = namespace
930937
? noDot
931938
? `${prefix}${symbol.name}`
932939
: `.${prefix}${symbol.name}`
933940
: symbol.name;
934941

942+
if (
943+
namespace &&
944+
namespace !== "*" &&
945+
this.configuration.completionSettings?.afterModule &&
946+
this.configuration.completionSettings.afterModule.startsWith("{module}")
947+
) {
948+
insertText = `${namespace}${insertText}`;
949+
}
950+
935951
const sortText = isPrivate ? label.replace(/^$[_]/, "") : undefined;
936952

937953
const documentation = {
@@ -1059,12 +1075,21 @@ export class DoComplete extends LanguageFeature {
10591075
initialDocument.languageId === "sass" ||
10601076
this.configuration.completionSettings?.afterModule === "";
10611077

1062-
const insertText = namespace
1078+
let insertText = namespace
10631079
? noDot
10641080
? `${prefix}${symbol.name}`
10651081
: `.${prefix}${symbol.name}`
10661082
: symbol.name;
10671083

1084+
if (
1085+
namespace &&
1086+
namespace !== "*" &&
1087+
this.configuration.completionSettings?.afterModule &&
1088+
this.configuration.completionSettings.afterModule.startsWith("{module}")
1089+
) {
1090+
insertText = `${namespace}${insertText}`;
1091+
}
1092+
10681093
const sortText = isPrivate ? label.replace(/^$[_]/, "") : undefined;
10691094

10701095
const documentation = {
@@ -1158,12 +1183,19 @@ export class DoComplete extends LanguageFeature {
11581183
document.languageId === "sass" ||
11591184
this.configuration.completionSettings?.afterModule === "";
11601185

1161-
const insertText = context.currentWord.includes(".")
1186+
let insertText = context.currentWord.includes(".")
11621187
? `${noDot ? "" : "."}${label}${
11631188
signature ? `(${parameterSnippet})` : ""
11641189
}`
11651190
: label;
11661191

1192+
if (
1193+
this.configuration.completionSettings?.afterModule &&
1194+
this.configuration.completionSettings.afterModule.startsWith("{module}")
1195+
) {
1196+
insertText = `${context.namespace}${insertText}`;
1197+
}
1198+
11671199
items.push({
11681200
documentation: {
11691201
kind: MarkupKind.Markdown,

packages/language-services/src/language-feature.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ export abstract class LanguageFeature {
7979
this.configuration = {
8080
...defaultConfiguration,
8181
...configuration,
82+
completionSettings: {
83+
...defaultConfiguration.completionSettings,
84+
...(configuration.completionSettings || {}),
85+
},
8286
};
8387
this._internal.sassLs.configure(configuration);
8488
}

packages/language-services/src/language-services-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export interface LanguageServiceConfiguration {
227227
includePrefixDot?: boolean;
228228
/**
229229
* If you end up with an extra `.` after accepting a suggestion, set this to the empty string.
230+
* If your module disappears, set it to "{module}" or "{module}." depending on your situation.
230231
*
231232
* @example
232233
* ```scss

0 commit comments

Comments
 (0)