@analogjs/language-server 0.1.2 → 0.1.4

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.
@@ -1,6 +1,6 @@
1
- import { type LanguagePlugin, type VirtualCode } from '@volar/language-core';
2
- import * as html from 'vscode-html-languageservice';
3
- import { URI } from 'vscode-uri';
1
+ import { type LanguagePlugin, type VirtualCode } from "@volar/language-core";
2
+ import * as html from "vscode-html-languageservice";
3
+ import { URI } from "vscode-uri";
4
4
  export declare const analogLanguagePlugin: LanguagePlugin<URI>;
5
5
  export interface AnalogVirtualCode extends VirtualCode {
6
6
  htmlDocument: html.HTMLDocument;
@@ -28,44 +28,50 @@ const language_core_1 = require("@volar/language-core");
28
28
  const html = __importStar(require("vscode-html-languageservice"));
29
29
  exports.analogLanguagePlugin = {
30
30
  getLanguageId(uri) {
31
- if (uri.path.endsWith('.analog')) {
32
- return 'analog';
31
+ if (uri.path.endsWith(".analog") || uri.path.endsWith(".ag")) {
32
+ return "analog";
33
33
  }
34
34
  },
35
35
  createVirtualCode(_uri, languageId, snapshot) {
36
- if (languageId === 'analog') {
36
+ if (languageId === "analog") {
37
37
  return createAnalogCode(snapshot);
38
38
  }
39
39
  },
40
40
  typescript: {
41
- extraFileExtensions: [{ extension: 'analog', isMixedContent: true, scriptKind: 3 }],
41
+ extraFileExtensions: [
42
+ {
43
+ extension: "analog",
44
+ isMixedContent: true,
45
+ scriptKind: 3,
46
+ },
47
+ ],
42
48
  getServiceScript() {
43
49
  return undefined;
44
50
  },
45
51
  getExtraServiceScripts(fileName, root) {
46
52
  const scripts = [];
47
53
  for (const code of (0, language_core_1.forEachEmbeddedCode)(root)) {
48
- if (code.languageId === 'javascript') {
54
+ if (code.languageId === "javascript") {
49
55
  scripts.push({
50
- fileName: fileName + '.' + code.id + '.js',
56
+ fileName: fileName + "." + code.id + ".js",
51
57
  code,
52
- extension: '.js',
58
+ extension: ".js",
53
59
  scriptKind: 1,
54
60
  });
55
61
  }
56
- else if (code.languageId === 'typescript') {
62
+ else if (code.languageId === "typescript") {
57
63
  scripts.push({
58
- fileName: fileName + '.' + code.id + '.ts',
64
+ fileName: fileName + "." + code.id + ".ts",
59
65
  code,
60
- extension: '.ts',
66
+ extension: ".ts",
61
67
  scriptKind: 3,
62
68
  });
63
69
  }
64
- else if (code.languageId === 'typescriptreact') {
70
+ else if (code.languageId === "typescriptreact") {
65
71
  scripts.push({
66
- fileName: fileName + '.' + code.id + '.tsx',
72
+ fileName: fileName + "." + code.id + ".tsx",
67
73
  code,
68
- extension: '.ts',
74
+ extension: ".ts",
69
75
  scriptKind: 4,
70
76
  });
71
77
  }
@@ -76,13 +82,14 @@ exports.analogLanguagePlugin = {
76
82
  };
77
83
  const htmlLs = html.getLanguageService();
78
84
  function createAnalogCode(snapshot) {
79
- const document = html.TextDocument.create('', 'html', 0, snapshot.getText(0, snapshot.getLength()));
85
+ const document = html.TextDocument.create("", "html", 0, snapshot.getText(0, snapshot.getLength()));
80
86
  const htmlDocument = htmlLs.parseHTMLDocument(document);
81
87
  return {
82
- id: 'root',
83
- languageId: 'html',
88
+ id: "root",
89
+ languageId: "html",
84
90
  snapshot,
85
- mappings: [{
91
+ mappings: [
92
+ {
86
93
  sourceOffsets: [0],
87
94
  generatedOffsets: [0],
88
95
  lengths: [snapshot.getLength()],
@@ -94,7 +101,8 @@ function createAnalogCode(snapshot) {
94
101
  structure: true,
95
102
  verification: true,
96
103
  },
97
- }],
104
+ },
105
+ ],
98
106
  embeddedCodes: [...createEmbeddedCodes()],
99
107
  htmlDocument,
100
108
  };
@@ -103,17 +111,20 @@ function createAnalogCode(snapshot) {
103
111
  let scripts = 0;
104
112
  let langs = 0;
105
113
  for (const root of htmlDocument.roots) {
106
- if (root.tag === 'style' && root.startTagEnd !== undefined && root.endTagStart !== undefined) {
114
+ if (root.tag === "style" &&
115
+ root.startTagEnd !== undefined &&
116
+ root.endTagStart !== undefined) {
107
117
  const styleText = snapshot.getText(root.startTagEnd, root.endTagStart);
108
118
  yield {
109
- id: 'style_' + styles++,
110
- languageId: 'css',
119
+ id: "style_" + styles++,
120
+ languageId: "css",
111
121
  snapshot: {
112
122
  getText: (start, end) => styleText.substring(start, end),
113
123
  getLength: () => styleText.length,
114
124
  getChangeRange: () => undefined,
115
125
  },
116
- mappings: [{
126
+ mappings: [
127
+ {
117
128
  sourceOffsets: [root.startTagEnd],
118
129
  generatedOffsets: [0],
119
130
  lengths: [styleText.length],
@@ -125,23 +136,42 @@ function createAnalogCode(snapshot) {
125
136
  structure: true,
126
137
  verification: true,
127
138
  },
128
- }],
139
+ },
140
+ ],
129
141
  embeddedCodes: [],
130
142
  };
131
143
  }
132
- if (root.tag === 'script' && root.startTagEnd !== undefined && root.endTagStart !== undefined) {
144
+ if (root.tag === "script" &&
145
+ root.startTagEnd !== undefined &&
146
+ root.endTagStart !== undefined) {
133
147
  const text = snapshot.getText(root.startTagEnd, root.endTagStart);
134
148
  const lang = root.attributes?.lang;
135
- const isTs = lang === 'ts' || lang === '"ts"' || lang === "'ts'";
149
+ const isTs = lang === "ts" || lang === '"ts"' || lang === "'ts'";
136
150
  yield {
137
- id: 'script_' + scripts++,
138
- languageId: isTs ? 'typescript' : 'javascript',
151
+ id: "script_" + scripts++,
152
+ languageId: isTs ? "typescript" : "javascript",
139
153
  snapshot: {
140
- getText: (start, end) => text.substring(start, end),
154
+ getText: (start, end) => `${text.substring(start, end)}
155
+ /**
156
+ * Defines additional metadata for the component such as the
157
+ * selector, providers, and more.
158
+ */
159
+ declare function defineMetadata(metadata: {}): void;
160
+ /**
161
+ * Defines the lifecycle hook(ngOnInit) that is called when the
162
+ * component is initialized.
163
+ */
164
+ declare function onInit(destroyFn: () => void): void;
165
+ /**
166
+ * Defines the lifecycle hook(ngOnDestroy) that is called when the
167
+ * component is destroyed.
168
+ */
169
+ declare function onDestroy(destroyFn: () => void): void;`,
141
170
  getLength: () => text.length,
142
171
  getChangeRange: () => undefined,
143
172
  },
144
- mappings: [{
173
+ mappings: [
174
+ {
145
175
  sourceOffsets: [root.startTagEnd],
146
176
  generatedOffsets: [0],
147
177
  lengths: [text.length],
@@ -153,23 +183,27 @@ function createAnalogCode(snapshot) {
153
183
  structure: true,
154
184
  verification: true,
155
185
  },
156
- }],
186
+ },
187
+ ],
157
188
  embeddedCodes: [],
158
189
  };
159
190
  }
160
- if (root.tag === 'template' && root.startTagEnd !== undefined && root.endTagStart !== undefined) {
191
+ if (root.tag === "template" &&
192
+ root.startTagEnd !== undefined &&
193
+ root.endTagStart !== undefined) {
161
194
  const text = snapshot.getText(root.startTagEnd, root.endTagStart);
162
195
  const lang = root.attributes?.lang;
163
- const isMd = lang === 'md' || lang === '"md"' || lang === "'md'";
196
+ const isMd = lang === "md" || lang === '"md"' || lang === "'md'";
164
197
  yield {
165
- id: 'lang_' + langs++,
166
- languageId: isMd ? 'markdown' : 'html',
198
+ id: "lang_" + langs++,
199
+ languageId: isMd ? "markdown" : "html",
167
200
  snapshot: {
168
201
  getText: (start, end) => text.substring(start, end),
169
202
  getLength: () => text.length,
170
203
  getChangeRange: () => undefined,
171
204
  },
172
- mappings: [{
205
+ mappings: [
206
+ {
173
207
  sourceOffsets: [root.startTagEnd],
174
208
  generatedOffsets: [0],
175
209
  lengths: [text.length],
@@ -181,12 +215,12 @@ function createAnalogCode(snapshot) {
181
215
  structure: true,
182
216
  verification: true,
183
217
  },
184
- }],
218
+ },
219
+ ],
185
220
  embeddedCodes: [],
186
221
  };
187
222
  }
188
223
  }
189
224
  }
190
- ;
191
225
  }
192
226
  //# sourceMappingURL=languagePlugin.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@analogjs/language-server",
3
3
  "description": "LSP server for AnalogJS Language Service",
4
- "version": "0.1.2",
4
+ "version": "0.1.4",
5
5
  "main": "out/index.js",
6
6
  "license": "MIT",
7
7
  "scripts": {