@astrojs/language-server 0.9.2 → 0.12.0

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.
Files changed (97) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/bin/browserServer.js +3 -0
  3. package/bin/nodeServer.js +3 -0
  4. package/dist/browser.d.ts +1 -0
  5. package/dist/browser.js +8 -0
  6. package/dist/check.js +2 -5
  7. package/dist/core/DiagnosticsManager.d.ts +3 -3
  8. package/dist/core/DiagnosticsManager.js +2 -2
  9. package/dist/core/config/ConfigManager.d.ts +19 -164
  10. package/dist/core/config/ConfigManager.js +62 -101
  11. package/dist/core/config/index.d.ts +1 -0
  12. package/dist/core/config/index.js +6 -1
  13. package/dist/core/config/interfaces.d.ts +123 -0
  14. package/dist/core/config/interfaces.js +2 -0
  15. package/dist/core/documents/AstroDocument.d.ts +18 -0
  16. package/dist/core/documents/AstroDocument.js +37 -0
  17. package/dist/core/documents/DocumentBase.d.ts +10 -2
  18. package/dist/core/documents/DocumentBase.js +15 -50
  19. package/dist/core/documents/DocumentManager.d.ts +12 -16
  20. package/dist/core/documents/DocumentManager.js +32 -26
  21. package/dist/core/documents/DocumentMapper.js +3 -1
  22. package/dist/core/documents/index.d.ts +1 -1
  23. package/dist/core/documents/index.js +6 -2
  24. package/dist/core/documents/parseAstro.d.ts +2 -2
  25. package/dist/core/documents/parseHtml.d.ts +2 -2
  26. package/dist/core/documents/parseHtml.js +4 -1
  27. package/dist/core/documents/utils.d.ts +22 -26
  28. package/dist/core/documents/utils.js +96 -134
  29. package/dist/index.d.ts +0 -1
  30. package/dist/index.js +1 -3
  31. package/dist/node.d.ts +1 -0
  32. package/dist/node.js +29 -0
  33. package/dist/plugins/PluginHost.d.ts +8 -9
  34. package/dist/plugins/PluginHost.js +22 -36
  35. package/dist/plugins/astro/AstroPlugin.d.ts +11 -12
  36. package/dist/plugins/astro/AstroPlugin.js +17 -38
  37. package/dist/plugins/astro/features/{CompletionProvider.d.ts → CompletionsProvider.d.ts} +5 -5
  38. package/dist/plugins/astro/features/{CompletionProvider.js → CompletionsProvider.js} +33 -54
  39. package/dist/plugins/css/CSSDocument.d.ts +3 -3
  40. package/dist/plugins/css/CSSDocument.js +7 -16
  41. package/dist/plugins/css/CSSPlugin.d.ts +19 -11
  42. package/dist/plugins/css/CSSPlugin.js +63 -41
  43. package/dist/plugins/css/StyleAttributeDocument.d.ts +2 -2
  44. package/dist/plugins/css/StyleAttributeDocument.js +2 -2
  45. package/dist/plugins/css/features/astro-selectors.d.ts +2 -0
  46. package/dist/plugins/css/features/astro-selectors.js +16 -0
  47. package/dist/plugins/css/features/{getIdClassCompletion.d.ts → getIdClassCompletions.d.ts} +3 -3
  48. package/dist/plugins/css/features/{getIdClassCompletion.js → getIdClassCompletions.js} +10 -9
  49. package/dist/plugins/css/{service.d.ts → language-service.d.ts} +0 -0
  50. package/dist/plugins/css/{service.js → language-service.js} +2 -1
  51. package/dist/plugins/html/HTMLPlugin.d.ts +15 -17
  52. package/dist/plugins/html/HTMLPlugin.js +33 -41
  53. package/dist/plugins/index.d.ts +2 -2
  54. package/dist/plugins/index.js +7 -3
  55. package/dist/plugins/interfaces.d.ts +35 -48
  56. package/dist/plugins/typescript/LanguageServiceManager.d.ts +33 -14
  57. package/dist/plugins/typescript/LanguageServiceManager.js +57 -32
  58. package/dist/plugins/typescript/TypeScriptPlugin.d.ts +16 -23
  59. package/dist/plugins/typescript/TypeScriptPlugin.js +48 -56
  60. package/dist/plugins/typescript/astro-sys.d.ts +5 -3
  61. package/dist/plugins/typescript/astro-sys.js +24 -41
  62. package/dist/plugins/typescript/features/CompletionsProvider.d.ts +6 -6
  63. package/dist/plugins/typescript/features/CompletionsProvider.js +17 -33
  64. package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +4 -4
  65. package/dist/plugins/typescript/features/DiagnosticsProvider.js +22 -61
  66. package/dist/plugins/typescript/features/HoverProvider.d.ts +4 -5
  67. package/dist/plugins/typescript/features/HoverProvider.js +9 -10
  68. package/dist/plugins/typescript/features/SignatureHelpProvider.d.ts +4 -5
  69. package/dist/plugins/typescript/features/SignatureHelpProvider.js +15 -11
  70. package/dist/plugins/typescript/features/utils.d.ts +1 -12
  71. package/dist/plugins/typescript/features/utils.js +2 -22
  72. package/dist/plugins/typescript/language-service.d.ts +38 -0
  73. package/dist/plugins/typescript/language-service.js +227 -0
  74. package/dist/plugins/typescript/module-loader.d.ts +5 -8
  75. package/dist/plugins/typescript/module-loader.js +43 -23
  76. package/dist/plugins/typescript/{DocumentSnapshot.d.ts → snapshots/DocumentSnapshot.d.ts} +45 -42
  77. package/dist/plugins/typescript/snapshots/DocumentSnapshot.js +135 -0
  78. package/dist/plugins/typescript/snapshots/SnapshotManager.d.ts +42 -0
  79. package/dist/plugins/typescript/snapshots/SnapshotManager.js +197 -0
  80. package/dist/plugins/typescript/snapshots/utils.d.ts +28 -0
  81. package/dist/plugins/typescript/snapshots/utils.js +84 -0
  82. package/dist/plugins/typescript/utils.d.ts +10 -11
  83. package/dist/plugins/typescript/utils.js +122 -151
  84. package/dist/server.d.ts +2 -4
  85. package/dist/server.js +88 -54
  86. package/dist/utils.d.ts +16 -8
  87. package/dist/utils.js +29 -14
  88. package/package.json +19 -13
  89. package/bin/server.js +0 -7
  90. package/dist/core/documents/Document.d.ts +0 -51
  91. package/dist/core/documents/Document.js +0 -135
  92. package/dist/plugins/typescript/DocumentSnapshot.js +0 -202
  93. package/dist/plugins/typescript/SnapshotManager.d.ts +0 -24
  94. package/dist/plugins/typescript/SnapshotManager.js +0 -97
  95. package/dist/plugins/typescript/languageService.d.ts +0 -17
  96. package/dist/plugins/typescript/languageService.js +0 -169
  97. package/types/index.d.ts +0 -4
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AstroDocument = void 0;
4
+ const utils_1 = require("../../utils");
5
+ const DocumentBase_1 = require("./DocumentBase");
6
+ const parseAstro_1 = require("./parseAstro");
7
+ const parseHtml_1 = require("./parseHtml");
8
+ const utils_2 = require("./utils");
9
+ class AstroDocument extends DocumentBase_1.WritableDocument {
10
+ constructor(url, content) {
11
+ super();
12
+ this.url = url;
13
+ this.content = content;
14
+ this.languageId = 'astro';
15
+ this.updateDocInfo();
16
+ }
17
+ updateDocInfo() {
18
+ this.astroMeta = (0, parseAstro_1.parseAstro)(this.content);
19
+ this.html = (0, parseHtml_1.parseHtml)(this.content);
20
+ this.styleTags = (0, utils_2.extractStyleTags)(this.content, this.html);
21
+ }
22
+ setText(text) {
23
+ this.content = text;
24
+ this.version++;
25
+ this.updateDocInfo();
26
+ }
27
+ getText() {
28
+ return this.content;
29
+ }
30
+ getURL() {
31
+ return this.url;
32
+ }
33
+ getFilePath() {
34
+ return (0, utils_1.urlToPath)(this.url);
35
+ }
36
+ }
37
+ exports.AstroDocument = AstroDocument;
@@ -1,4 +1,5 @@
1
- import { Position, TextDocument } from 'vscode-languageserver';
1
+ import { Position } from 'vscode-languageserver';
2
+ import { TextDocument } from 'vscode-languageserver-textdocument';
2
3
  /**
3
4
  * Represents a textual document.
4
5
  */
@@ -19,6 +20,10 @@ export declare abstract class ReadableDocument implements TextDocument {
19
20
  * Current version of the document.
20
21
  */
21
22
  version: number;
23
+ /**
24
+ * Should be cleared when there's an update to the text
25
+ */
26
+ protected lineOffsets?: number[];
22
27
  /**
23
28
  * Get the length of the document's content
24
29
  */
@@ -33,11 +38,13 @@ export declare abstract class ReadableDocument implements TextDocument {
33
38
  * @param position Line and character position
34
39
  */
35
40
  offsetAt(position: Position): number;
41
+ getLineUntilOffset(offset: number): string;
36
42
  private getLineOffsets;
37
43
  /**
38
44
  * Implements TextDocument
39
45
  */
40
46
  get uri(): string;
47
+ get lines(): string[];
41
48
  get lineCount(): number;
42
49
  abstract languageId: string;
43
50
  }
@@ -46,7 +53,8 @@ export declare abstract class ReadableDocument implements TextDocument {
46
53
  */
47
54
  export declare abstract class WritableDocument extends ReadableDocument {
48
55
  /**
49
- * Set the text content of the document
56
+ * Set the text content of the document.
57
+ * Implementers should set `lineOffsets` to `undefined` here.
50
58
  * @param text The new text content
51
59
  */
52
60
  abstract setText(text: string): void;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WritableDocument = exports.ReadableDocument = void 0;
4
- const utils_1 = require("../../utils");
5
- const vscode_languageserver_1 = require("vscode-languageserver");
4
+ const utils_1 = require("./utils");
6
5
  /**
7
6
  * Represents a textual document.
8
7
  */
@@ -24,62 +23,24 @@ class ReadableDocument {
24
23
  * @param offset The index of the position
25
24
  */
26
25
  positionAt(offset) {
27
- offset = (0, utils_1.clamp)(offset, 0, this.getTextLength());
28
- const lineOffsets = this.getLineOffsets();
29
- let low = 0;
30
- let high = lineOffsets.length;
31
- if (high === 0) {
32
- return vscode_languageserver_1.Position.create(0, offset);
33
- }
34
- while (low < high) {
35
- const mid = Math.floor((low + high) / 2);
36
- if (lineOffsets[mid] > offset) {
37
- high = mid;
38
- }
39
- else {
40
- low = mid + 1;
41
- }
42
- }
43
- // low is the least x for which the line offset is larger than the current offset
44
- // or array.length if no line offset is larger than the current offset
45
- const line = low - 1;
46
- return vscode_languageserver_1.Position.create(line, offset - lineOffsets[line]);
26
+ return (0, utils_1.positionAt)(offset, this.getText(), this.getLineOffsets());
47
27
  }
48
28
  /**
49
29
  * Get the index of the line and character position
50
30
  * @param position Line and character position
51
31
  */
52
32
  offsetAt(position) {
53
- const lineOffsets = this.getLineOffsets();
54
- if (position.line >= lineOffsets.length) {
55
- return this.getTextLength();
56
- }
57
- else if (position.line < 0) {
58
- return 0;
59
- }
60
- const lineOffset = lineOffsets[position.line];
61
- const nextLineOffset = position.line + 1 < lineOffsets.length ? lineOffsets[position.line + 1] : this.getTextLength();
62
- return (0, utils_1.clamp)(nextLineOffset, lineOffset, lineOffset + position.character);
33
+ return (0, utils_1.offsetAt)(position, this.getText(), this.getLineOffsets());
34
+ }
35
+ getLineUntilOffset(offset) {
36
+ const { line, character } = this.positionAt(offset);
37
+ return this.lines[line].slice(0, character);
63
38
  }
64
39
  getLineOffsets() {
65
- const lineOffsets = [];
66
- const text = this.getText();
67
- let isLineStart = true;
68
- for (let i = 0; i < text.length; i++) {
69
- if (isLineStart) {
70
- lineOffsets.push(i);
71
- isLineStart = false;
72
- }
73
- const ch = text.charAt(i);
74
- isLineStart = ch === '\r' || ch === '\n';
75
- if (ch === '\r' && i + 1 < text.length && text.charAt(i + 1) === '\n') {
76
- i++;
77
- }
78
- }
79
- if (isLineStart && text.length > 0) {
80
- lineOffsets.push(text.length);
40
+ if (!this.lineOffsets) {
41
+ this.lineOffsets = (0, utils_1.getLineOffsets)(this.getText());
81
42
  }
82
- return lineOffsets;
43
+ return this.lineOffsets;
83
44
  }
84
45
  /**
85
46
  * Implements TextDocument
@@ -87,8 +48,11 @@ class ReadableDocument {
87
48
  get uri() {
88
49
  return this.getURL();
89
50
  }
51
+ get lines() {
52
+ return this.getText().split(/\r?\n/);
53
+ }
90
54
  get lineCount() {
91
- return this.getText().split(/\r?\n/).length;
55
+ return this.lines.length;
92
56
  }
93
57
  }
94
58
  exports.ReadableDocument = ReadableDocument;
@@ -103,6 +67,7 @@ class WritableDocument extends ReadableDocument {
103
67
  * @param end End offset of the new text
104
68
  */
105
69
  update(text, start, end) {
70
+ this.lineOffsets = undefined;
106
71
  const content = this.getText();
107
72
  this.setText(content.slice(0, start) + text + content.slice(end));
108
73
  }
@@ -1,27 +1,23 @@
1
- import { TextDocumentContentChangeEvent, TextDocumentItem } from 'vscode-languageserver';
2
- import { Document } from './Document';
1
+ import { TextDocumentContentChangeEvent, TextDocumentItem, VersionedTextDocumentIdentifier } from 'vscode-languageserver';
2
+ import { AstroDocument } from './AstroDocument';
3
3
  export declare type DocumentEvent = 'documentOpen' | 'documentChange' | 'documentClose';
4
4
  export declare class DocumentManager {
5
- private createDocument;
5
+ private createDocument?;
6
6
  private emitter;
7
7
  private openedInClient;
8
8
  private documents;
9
9
  private locked;
10
10
  private deleteCandidates;
11
- constructor(createDocument: (textDocument: {
12
- uri: string;
13
- text: string;
14
- }) => Document);
15
- get(uri: string): Document | undefined;
16
- openDocument(textDocument: TextDocumentItem & {
17
- overrideText: boolean;
18
- }): Document;
19
- closeDocument(uri: string): void;
20
- releaseDocument(uri: string): void;
21
- updateDocument(uri: string, changes: TextDocumentContentChangeEvent[]): void;
11
+ constructor(createDocument?: ((textDocument: Pick<TextDocumentItem, 'text' | 'uri'>) => AstroDocument) | undefined);
12
+ openDocument(textDocument: Pick<TextDocumentItem, 'text' | 'uri'>): AstroDocument;
13
+ lockDocument(uri: string): void;
22
14
  markAsOpenedInClient(uri: string): void;
23
- getAllOpenedByClient(): [string, Document][];
24
- on(name: DocumentEvent, listener: (document: Document) => void): void;
15
+ getAllOpenedByClient(): [string, AstroDocument][];
16
+ releaseDocument(uri: string): void;
17
+ closeDocument(uri: string): void;
18
+ updateDocument(textDocument: VersionedTextDocumentIdentifier, changes: TextDocumentContentChangeEvent[]): void;
19
+ on(name: DocumentEvent, listener: (document: AstroDocument) => void): void;
20
+ get(uri: string): AstroDocument | undefined;
25
21
  private notify;
26
22
  static newInstance(): DocumentManager;
27
23
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DocumentManager = void 0;
4
4
  const events_1 = require("events");
5
- const Document_1 = require("./Document");
5
+ const AstroDocument_1 = require("./AstroDocument");
6
6
  const utils_1 = require("../../utils");
7
7
  class DocumentManager {
8
8
  constructor(createDocument) {
@@ -12,25 +12,43 @@ class DocumentManager {
12
12
  this.documents = new Map();
13
13
  this.locked = new Set();
14
14
  this.deleteCandidates = new Set();
15
- }
16
- get(uri) {
17
- return this.documents.get((0, utils_1.normalizeUri)(uri));
15
+ if (!createDocument) {
16
+ this.createDocument = (textDocument) => new AstroDocument_1.AstroDocument(textDocument.uri, textDocument.text);
17
+ }
18
18
  }
19
19
  openDocument(textDocument) {
20
+ textDocument = { ...textDocument, uri: (0, utils_1.normalizeUri)(textDocument.uri) };
20
21
  let document;
21
22
  if (this.documents.has(textDocument.uri)) {
22
- document = this.get(textDocument.uri);
23
- if (textDocument.overrideText)
24
- document.setText(textDocument.text);
23
+ document = this.documents.get(textDocument.uri);
24
+ document.setText(textDocument.text);
25
25
  }
26
26
  else {
27
27
  document = this.createDocument(textDocument);
28
- this.documents.set((0, utils_1.normalizeUri)(textDocument.uri), document);
28
+ this.documents.set(textDocument.uri, document);
29
29
  this.notify('documentOpen', document);
30
30
  }
31
31
  this.notify('documentChange', document);
32
32
  return document;
33
33
  }
34
+ lockDocument(uri) {
35
+ this.locked.add((0, utils_1.normalizeUri)(uri));
36
+ }
37
+ markAsOpenedInClient(uri) {
38
+ this.openedInClient.add((0, utils_1.normalizeUri)(uri));
39
+ }
40
+ getAllOpenedByClient() {
41
+ return Array.from(this.documents.entries()).filter((doc) => this.openedInClient.has(doc[0]));
42
+ }
43
+ releaseDocument(uri) {
44
+ uri = (0, utils_1.normalizeUri)(uri);
45
+ this.locked.delete(uri);
46
+ this.openedInClient.delete(uri);
47
+ if (this.deleteCandidates.has(uri)) {
48
+ this.deleteCandidates.delete(uri);
49
+ this.closeDocument(uri);
50
+ }
51
+ }
34
52
  closeDocument(uri) {
35
53
  uri = (0, utils_1.normalizeUri)(uri);
36
54
  const document = this.documents.get(uri);
@@ -47,17 +65,8 @@ class DocumentManager {
47
65
  }
48
66
  this.openedInClient.delete(uri);
49
67
  }
50
- releaseDocument(uri) {
51
- uri = (0, utils_1.normalizeUri)(uri);
52
- this.locked.delete(uri);
53
- this.openedInClient.delete(uri);
54
- if (this.deleteCandidates.has(uri)) {
55
- this.deleteCandidates.delete(uri);
56
- this.closeDocument(uri);
57
- }
58
- }
59
- updateDocument(uri, changes) {
60
- const document = this.documents.get((0, utils_1.normalizeUri)(uri));
68
+ updateDocument(textDocument, changes) {
69
+ const document = this.documents.get((0, utils_1.normalizeUri)(textDocument.uri));
61
70
  if (!document) {
62
71
  throw new Error('Cannot call methods on an unopened document');
63
72
  }
@@ -75,20 +84,17 @@ class DocumentManager {
75
84
  }
76
85
  this.notify('documentChange', document);
77
86
  }
78
- markAsOpenedInClient(uri) {
79
- this.openedInClient.add((0, utils_1.normalizeUri)(uri));
80
- }
81
- getAllOpenedByClient() {
82
- return Array.from(this.documents.entries()).filter((doc) => this.openedInClient.has(doc[0]));
83
- }
84
87
  on(name, listener) {
85
88
  this.emitter.on(name, listener);
86
89
  }
90
+ get(uri) {
91
+ return this.documents.get((0, utils_1.normalizeUri)(uri));
92
+ }
87
93
  notify(name, document) {
88
94
  this.emitter.emit(name, document);
89
95
  }
90
96
  static newInstance() {
91
- return new DocumentManager(({ uri, text }) => new Document_1.Document(uri, text));
97
+ return new DocumentManager(({ uri, text }) => new AstroDocument_1.AstroDocument(uri, text));
92
98
  }
93
99
  }
94
100
  exports.DocumentManager = DocumentManager;
@@ -213,7 +213,9 @@ function mapSymbolInformationToOriginal(fragment, info) {
213
213
  }
214
214
  exports.mapSymbolInformationToOriginal = mapSymbolInformationToOriginal;
215
215
  function mapLocationLinkToOriginal(fragment, def) {
216
- return vscode_languageserver_1.LocationLink.create(def.targetUri, fragment.getURL() === def.targetUri ? mapRangeToOriginal(fragment, def.targetRange) : def.targetRange, fragment.getURL() === def.targetUri ? mapRangeToOriginal(fragment, def.targetSelectionRange) : def.targetSelectionRange, def.originSelectionRange ? mapRangeToOriginal(fragment, def.originSelectionRange) : undefined);
216
+ return vscode_languageserver_1.LocationLink.create(def.targetUri, fragment.getURL() === def.targetUri ? mapRangeToOriginal(fragment, def.targetRange) : def.targetRange, fragment.getURL() === def.targetUri
217
+ ? mapRangeToOriginal(fragment, def.targetSelectionRange)
218
+ : def.targetSelectionRange, def.originSelectionRange ? mapRangeToOriginal(fragment, def.originSelectionRange) : undefined);
217
219
  }
218
220
  exports.mapLocationLinkToOriginal = mapLocationLinkToOriginal;
219
221
  function mapTextDocumentEditToOriginal(fragment, edit) {
@@ -1,4 +1,4 @@
1
- export * from './Document';
1
+ export * from './AstroDocument';
2
2
  export * from './DocumentBase';
3
3
  export * from './DocumentManager';
4
4
  export * from './DocumentMapper';
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -10,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
15
  };
12
16
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./Document"), exports);
17
+ __exportStar(require("./AstroDocument"), exports);
14
18
  __exportStar(require("./DocumentBase"), exports);
15
19
  __exportStar(require("./DocumentManager"), exports);
16
20
  __exportStar(require("./DocumentMapper"), exports);
@@ -6,10 +6,10 @@ interface Frontmatter {
6
6
  interface Content {
7
7
  firstNonWhitespaceOffset: null | number;
8
8
  }
9
- export interface AstroDocument {
9
+ export interface AstroMetadata {
10
10
  frontmatter: Frontmatter;
11
11
  content: Content;
12
12
  }
13
13
  /** Parses a document to collect metadata about Astro features */
14
- export declare function parseAstro(content: string): AstroDocument;
14
+ export declare function parseAstro(content: string): AstroMetadata;
15
15
  export {};
@@ -1,5 +1,5 @@
1
1
  import { HTMLDocument, Position } from 'vscode-html-languageservice';
2
- import { Document } from './Document';
2
+ import { AstroDocument } from './AstroDocument';
3
3
  /**
4
4
  * Parses text as HTML
5
5
  */
@@ -9,4 +9,4 @@ export interface AttributeContext {
9
9
  inValue: boolean;
10
10
  valueRange?: [number, number];
11
11
  }
12
- export declare function getAttributeContextAtPosition(document: Document, position: Position): AttributeContext | null;
12
+ export declare function getAttributeContextAtPosition(document: AstroDocument, position: Position): AttributeContext | null;
@@ -40,7 +40,10 @@ function preprocess(text) {
40
40
  }
41
41
  // <Foo checked={a < 1}>
42
42
  // https://github.com/microsoft/vscode-html-languageservice/blob/71806ef57be07e1068ee40900ef8b0899c80e68a/src/parser/htmlScanner.ts#L327
43
- if (token === vscode_html_languageservice_1.TokenType.Unknown && scanner.getScannerState() === vscode_html_languageservice_1.ScannerState.WithinTag && scanner.getTokenText() === '<' && shouldBlankStartOrEndTagLike(offset)) {
43
+ if (token === vscode_html_languageservice_1.TokenType.Unknown &&
44
+ scanner.getScannerState() === vscode_html_languageservice_1.ScannerState.WithinTag &&
45
+ scanner.getTokenText() === '<' &&
46
+ shouldBlankStartOrEndTagLike(offset)) {
44
47
  blankStartOrEndTagLike(offset);
45
48
  }
46
49
  token = scanner.scan();
@@ -1,4 +1,5 @@
1
- import { HTMLDocument, Node, Position } from 'vscode-html-languageservice';
1
+ import { Position } from 'vscode-languageserver';
2
+ import { HTMLDocument, Node } from 'vscode-html-languageservice';
2
3
  export interface TagInformation {
3
4
  content: string;
4
5
  attributes: Record<string, string>;
@@ -11,49 +12,44 @@ export interface TagInformation {
11
12
  end: number;
12
13
  };
13
14
  }
15
+ export declare function walk(node: Node): Generator<Node, void, unknown>;
16
+ export declare function extractStyleTags(source: string, html?: HTMLDocument): TagInformation[];
14
17
  /**
15
- * Gets word range at position.
16
- * Delimiter is by default a whitespace, but can be adjusted.
18
+ * Return if a Node is a Component
17
19
  */
18
- export declare function getWordRangeAt(str: string, pos: number, delimiterRegex?: {
19
- left: RegExp;
20
- right: RegExp;
21
- }): {
22
- start: number;
23
- end: number;
24
- };
20
+ export declare function isComponentTag(node: Node): boolean;
25
21
  /**
26
- * Gets word at position.
27
- * Delimiter is by default a whitespace, but can be adjusted.
22
+ * Return if a given offset is inside the start tag of a component
28
23
  */
29
- export declare function getWordAt(str: string, pos: number, delimiterRegex?: {
30
- left: RegExp;
31
- right: RegExp;
32
- }): string;
24
+ export declare function isInComponentStartTag(html: HTMLDocument, offset: number): boolean;
33
25
  /**
34
- * Gets index of first-non-whitespace character.
26
+ * Return if the current position is in a specific tag
27
+ */
28
+ export declare function isInTag(position: Position, tagInfo: TagInformation | null): tagInfo is TagInformation;
29
+ /**
30
+ * Return if a given position is inside a JSX expression
35
31
  */
36
- export declare function getFirstNonWhitespaceIndex(str: string): number;
37
- /** checks if a position is currently inside of an expression */
38
32
  export declare function isInsideExpression(html: string, tagStart: number, position: number): boolean;
39
33
  /**
40
34
  * Returns if a given offset is inside of the document frontmatter
41
35
  */
42
36
  export declare function isInsideFrontmatter(text: string, offset: number): boolean;
43
- export declare function isInTag(position: Position, tagInfo: TagInformation | null): tagInfo is TagInformation;
44
- export declare function isComponentTag(node: Node): boolean;
45
- export declare function isInComponentStartTag(html: HTMLDocument, offset: number): boolean;
46
37
  /**
47
38
  * Get the line and character based on the offset
48
39
  * @param offset The index of the position
49
40
  * @param text The text for which the position should be retrived
41
+ * @param lineOffsets number Array with offsets for each line. Computed if not given
50
42
  */
51
- export declare function positionAt(offset: number, text: string): Position;
43
+ export declare function positionAt(offset: number, text: string, lineOffsets?: number[]): Position;
52
44
  /**
53
45
  * Get the offset of the line and character position
54
46
  * @param position Line and character position
55
47
  * @param text The text for which the offset should be retrived
48
+ * @param lineOffsets number Array with offsets for each line. Computed if not given
56
49
  */
57
- export declare function offsetAt(position: Position, text: string): number;
58
- export declare function walk(node: Node): Generator<Node, void, unknown>;
59
- export declare function extractStyleTag(source: string, html?: HTMLDocument): TagInformation | null;
50
+ export declare function offsetAt(position: Position, text: string, lineOffsets?: number[]): number;
51
+ export declare function getLineOffsets(text: string): number[];
52
+ /**
53
+ * Gets index of first-non-whitespace character.
54
+ */
55
+ export declare function getFirstNonWhitespaceIndex(str: string): number;