@astrojs/language-server 0.19.2 → 0.19.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @astrojs/language-server
2
2
 
3
+ ## 0.19.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 49ff4ef: Fixed more bugs where nonexistent server settings would result in a crash
8
+ - 14cbf05: Fix frontmatter completion not working when three dashes were already present
9
+
3
10
  ## 0.19.2
4
11
 
5
12
  ### Patch Changes
@@ -142,8 +142,15 @@ class ConfigManager {
142
142
  * Return true if a plugin and an optional feature is enabled
143
143
  */
144
144
  async isEnabled(document, plugin, feature) {
145
- const config = await this.getConfig('astro', document.uri);
146
- return feature ? config[plugin].enabled && config[plugin][feature].enabled : config[plugin].enabled;
145
+ const config = (await this.getConfig('astro', document.uri)) ?? {};
146
+ if (config[plugin]) {
147
+ let res = config[plugin].enabled;
148
+ if (feature && config[plugin][feature]) {
149
+ res = res && config[plugin][feature].enabled;
150
+ }
151
+ return res;
152
+ }
153
+ return false;
147
154
  }
148
155
  /**
149
156
  * Updating the global config should only be done in cases where the client doesn't support `workspace/configuration`
@@ -23,15 +23,16 @@ class CompletionsProviderImpl {
23
23
  }
24
24
  async getCompletions(document, position, completionContext) {
25
25
  let items = [];
26
- if (completionContext?.triggerCharacter === '-') {
26
+ const html = document.html;
27
+ const offset = document.offsetAt(position);
28
+ const node = html.findNodeAt(offset);
29
+ const insideExpression = (0, utils_1.isInsideExpression)(document.getText(), node.start, offset);
30
+ if (completionContext?.triggerCharacter === '-' && node.parent === undefined && !insideExpression) {
27
31
  const frontmatter = this.getComponentScriptCompletion(document, position);
28
32
  if (frontmatter)
29
33
  items.push(frontmatter);
30
34
  }
31
- const html = document.html;
32
- const offset = document.offsetAt(position);
33
- const node = html.findNodeAt(offset);
34
- if ((0, utils_1.isInComponentStartTag)(html, offset) && !(0, utils_1.isInsideExpression)(document.getText(), node.start, offset)) {
35
+ if ((0, utils_1.isInComponentStartTag)(html, offset) && !insideExpression) {
35
36
  const { completions: props, componentFilePath } = await this.getPropCompletionsAndFilePath(document, position, completionContext);
36
37
  if (props.length) {
37
38
  items.push(...props);
@@ -50,7 +51,7 @@ class CompletionsProviderImpl {
50
51
  label: '---',
51
52
  sortText: '\0',
52
53
  preselect: true,
53
- detail: 'Component script',
54
+ detail: 'Create component script block',
54
55
  insertTextFormat: vscode_languageserver_1.InsertTextFormat.Snippet,
55
56
  commitCharacters: [],
56
57
  };
@@ -65,11 +66,18 @@ class CompletionsProviderImpl {
65
66
  };
66
67
  }
67
68
  if (document.astroMeta.frontmatter.state === 'open') {
69
+ let insertText = '---';
70
+ // If the current line is a full component script starter/ender, the user expects a full frontmatter
71
+ // completion and not just a completion for "---" on the same line (which result in, well, nothing)
72
+ if (prefix === '---') {
73
+ insertText = '---\n$0\n---';
74
+ }
68
75
  return {
69
76
  ...base,
70
- insertText: '---',
77
+ insertText,
78
+ detail: insertText === '---' ? 'Close component script block' : 'Create component script block',
71
79
  textEdit: prefix.match(/^\s*\-+/)
72
- ? vscode_languageserver_1.TextEdit.replace({ start: { ...position, character: 0 }, end: position }, '---')
80
+ ? vscode_languageserver_1.TextEdit.replace({ start: { ...position, character: 0 }, end: position }, insertText)
73
81
  : undefined,
74
82
  };
75
83
  }
@@ -63,8 +63,8 @@ class HTMLPlugin {
63
63
  items: [],
64
64
  };
65
65
  const emmetConfig = await this.configManager.getEmmetConfig(document);
66
- const extensionConfig = await this.configManager.getConfig('astro', document.uri);
67
- if (extensionConfig.html.completions.emmet) {
66
+ const extensionConfig = (await this.configManager.getConfig('astro', document.uri)) ?? {};
67
+ if (extensionConfig?.html?.completions?.emmet) {
68
68
  this.lang.setCompletionParticipants([
69
69
  {
70
70
  onHtmlContent: () => (emmetResults = (0, emmet_helper_1.doComplete)(document, position, 'html', emmetConfig) || emmetResults),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "0.19.2",
3
+ "version": "0.19.3",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",