@astrojs/language-server 1.0.0 → 1.0.1

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 (27) hide show
  1. package/dist/core/DiagnosticsManager.d.ts +2 -2
  2. package/dist/core/config/ConfigManager.d.ts +1 -1
  3. package/dist/core/documents/DocumentManager.d.ts +1 -1
  4. package/dist/plugins/css/features/getIdClassCompletions.d.ts +1 -1
  5. package/dist/plugins/interfaces.d.ts +4 -4
  6. package/dist/plugins/typescript/LanguageServiceManager.d.ts +2 -1
  7. package/dist/plugins/typescript/TypeScriptPlugin.js +2 -5
  8. package/dist/plugins/typescript/astro-sys.d.ts +2 -1
  9. package/dist/plugins/typescript/astro2tsx.d.ts +1 -1
  10. package/dist/plugins/typescript/astro2tsx.js +23 -5
  11. package/dist/plugins/typescript/features/CompletionsProvider.d.ts +1 -1
  12. package/dist/plugins/typescript/features/DiagnosticsProvider.d.ts +1 -0
  13. package/dist/plugins/typescript/features/DiagnosticsProvider.js +2 -0
  14. package/dist/plugins/typescript/features/SignatureHelpProvider.js +1 -1
  15. package/dist/plugins/typescript/language-service.d.ts +1 -0
  16. package/dist/plugins/typescript/module-loader.d.ts +2 -1
  17. package/dist/plugins/typescript/module-loader.js +6 -3
  18. package/dist/plugins/typescript/previewer.d.ts +4 -0
  19. package/dist/plugins/typescript/previewer.js +0 -3
  20. package/dist/plugins/typescript/snapshots/DocumentSnapshot.d.ts +1 -0
  21. package/dist/plugins/typescript/snapshots/utils.js +2 -5
  22. package/dist/plugins/typescript/utils.d.ts +3 -2
  23. package/package.json +3 -4
  24. package/dist/core/worker/TSXService.d.ts +0 -7
  25. package/dist/core/worker/TSXService.js +0 -12
  26. package/dist/core/worker/TSXWorker.d.ts +0 -1
  27. package/dist/core/worker/TSXWorker.js +0 -9
@@ -1,7 +1,7 @@
1
1
  import type { Connection, Diagnostic, TextDocumentIdentifier } from 'vscode-languageserver';
2
2
  import type { AstroDocument, DocumentManager } from './documents';
3
- export declare type SendDiagnostics = Connection['sendDiagnostics'];
4
- export declare type GetDiagnostics = (doc: TextDocumentIdentifier) => Thenable<Diagnostic[]>;
3
+ export type SendDiagnostics = Connection['sendDiagnostics'];
4
+ export type GetDiagnostics = (doc: TextDocumentIdentifier) => Thenable<Diagnostic[]>;
5
5
  export declare class DiagnosticsManager {
6
6
  private sendDiagnostics;
7
7
  private docManager;
@@ -4,7 +4,7 @@ import type { Connection, FormattingOptions } from 'vscode-languageserver';
4
4
  import type { TextDocument } from 'vscode-languageserver-textdocument';
5
5
  import type { LSConfig, LSCSSConfig, LSHTMLConfig, LSTypescriptConfig } from './interfaces';
6
6
  export declare const defaultLSConfig: LSConfig;
7
- declare type DeepPartial<T> = T extends Record<string, unknown> ? {
7
+ type DeepPartial<T> = T extends Record<string, unknown> ? {
8
8
  [P in keyof T]?: DeepPartial<T[P]>;
9
9
  } : T;
10
10
  /**
@@ -1,6 +1,6 @@
1
1
  import type { TextDocumentContentChangeEvent, TextDocumentItem, VersionedTextDocumentIdentifier } from 'vscode-languageserver';
2
2
  import { AstroDocument } from './AstroDocument';
3
- export declare type DocumentEvent = 'documentOpen' | 'documentChange' | 'documentClose';
3
+ export type DocumentEvent = 'documentOpen' | 'documentChange' | 'documentClose';
4
4
  export declare class DocumentManager {
5
5
  private createDocument?;
6
6
  private emitter;
@@ -11,7 +11,7 @@ export declare enum NodeType {
11
11
  ClassSelector = 14,
12
12
  IdentifierSelector = 15
13
13
  }
14
- export declare type CSSNode = {
14
+ export type CSSNode = {
15
15
  type: number;
16
16
  children: CSSNode[] | undefined;
17
17
  getText(): string;
@@ -1,6 +1,6 @@
1
1
  import type { CodeAction, CodeActionContext, Color, ColorInformation, ColorPresentation, CompletionContext, CompletionItem, CompletionList, DefinitionLink, Diagnostic, FileChangeType, FoldingRange, FormattingOptions, Hover, InlayHint, LinkedEditingRanges, Location, Position, Range, ReferenceContext, SelectionRange, SemanticTokens, SignatureHelp, SignatureHelpContext, SymbolInformation, TextDocumentContentChangeEvent, TextDocumentIdentifier, TextEdit, WorkspaceEdit } from 'vscode-languageserver';
2
2
  import type { TextDocument } from 'vscode-languageserver-textdocument';
3
- export declare type Resolvable<T> = T | Promise<T>;
3
+ export type Resolvable<T> = T | Promise<T>;
4
4
  export interface AppCompletionItem<T extends TextDocumentIdentifier = any> extends CompletionItem {
5
5
  data?: T;
6
6
  }
@@ -93,9 +93,9 @@ export interface OnWatchFileChangesProvider {
93
93
  export interface UpdateNonAstroFile {
94
94
  updateNonAstroFile(fileName: string, changes: TextDocumentContentChangeEvent[], text?: string): void;
95
95
  }
96
- declare type ProviderBase = DiagnosticsProvider & HoverProvider & CompletionsProvider & FileReferencesProvider & DefinitionsProvider & TypeDefinitionsProvider & ImplementationProvider & FormattingProvider & FoldingRangesProvider & TagCompleteProvider & DocumentColorsProvider & ColorPresentationsProvider & DocumentSymbolsProvider & UpdateImportsProvider & CodeActionsProvider & FindReferencesProvider & RenameProvider & SignatureHelpProvider & SemanticTokensProvider & SelectionRangeProvider & OnWatchFileChangesProvider & LinkedEditingRangesProvider & InlayHintsProvider & UpdateNonAstroFile;
97
- export declare type LSProvider = ProviderBase;
98
- export declare type Plugin = Partial<ProviderBase> & {
96
+ type ProviderBase = DiagnosticsProvider & HoverProvider & CompletionsProvider & FileReferencesProvider & DefinitionsProvider & TypeDefinitionsProvider & ImplementationProvider & FormattingProvider & FoldingRangesProvider & TagCompleteProvider & DocumentColorsProvider & ColorPresentationsProvider & DocumentSymbolsProvider & UpdateImportsProvider & CodeActionsProvider & FindReferencesProvider & RenameProvider & SignatureHelpProvider & SemanticTokensProvider & SelectionRangeProvider & OnWatchFileChangesProvider & LinkedEditingRangesProvider & InlayHintsProvider & UpdateNonAstroFile;
97
+ export type LSProvider = ProviderBase;
98
+ export type Plugin = Partial<ProviderBase> & {
99
99
  __name: string;
100
100
  };
101
101
  export {};
@@ -1,3 +1,4 @@
1
+ import type ts from 'typescript';
1
2
  import type { TextDocumentContentChangeEvent } from 'vscode-languageserver';
2
3
  import type { ConfigManager } from '../../core/config';
3
4
  import type { AstroDocument, DocumentManager } from '../../core/documents';
@@ -37,7 +38,7 @@ export declare class LanguageServiceManager {
37
38
  tsDoc: DocumentSnapshot;
38
39
  lang: ts.LanguageService;
39
40
  }>;
40
- getLSForPath(path: string): Promise<import("typescript/lib/tsserverlibrary").LanguageService>;
41
+ getLSForPath(path: string): Promise<ts.LanguageService>;
41
42
  getTypeScriptLanguageService(filePath: string): Promise<LanguageServiceContainer>;
42
43
  /**
43
44
  * @internal Public for tests only
@@ -1,11 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.TypeScriptPlugin = void 0;
7
4
  const vscode_languageserver_1 = require("vscode-languageserver");
8
- const astro2tsx_1 = __importDefault(require("./astro2tsx"));
5
+ const astro2tsx_1 = require("./astro2tsx");
9
6
  const CodeActionsProvider_1 = require("./features/CodeActionsProvider");
10
7
  const CompletionsProvider_1 = require("./features/CompletionsProvider");
11
8
  const DefinitionsProvider_1 = require("./features/DefinitionsProvider");
@@ -139,7 +136,7 @@ class TypeScriptPlugin {
139
136
  return this.signatureHelpProvider.getSignatureHelp(document, position, context, cancellationToken);
140
137
  }
141
138
  getTSXForDocument(document) {
142
- return (0, astro2tsx_1.default)(document.getText(), document.getURL());
139
+ return (0, astro2tsx_1.astro2tsx)(document.getText(), document.getURL());
143
140
  }
144
141
  /**
145
142
  * @internal Public for tests only
@@ -1,7 +1,8 @@
1
+ import type ts from 'typescript';
1
2
  import type { DocumentSnapshot } from './snapshots/DocumentSnapshot';
2
3
  /**
3
4
  * This should only be accessed by TS Astro module resolution.
4
5
  */
5
- export declare function createAstroSys(getSnapshot: (fileName: string) => DocumentSnapshot, ts: typeof import('typescript/lib/tsserverlibrary')): import("typescript/lib/tsserverlibrary").System & {
6
+ export declare function createAstroSys(getSnapshot: (fileName: string) => DocumentSnapshot, ts: typeof import('typescript/lib/tsserverlibrary')): ts.System & {
6
7
  deleteFromCache: (path: string) => void;
7
8
  };
@@ -1,2 +1,2 @@
1
1
  import type { TSXResult } from '@astrojs/compiler/types';
2
- export default function (content: string, fileName: string): TSXResult;
2
+ export declare function astro2tsx(content: string, fileName: string): TSXResult;
@@ -1,8 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const TSXService_1 = require("../../core/worker/TSXService");
4
- function default_1(content, fileName) {
5
- const tsx = (0, TSXService_1.convertToTSX)(content, { filename: fileName });
6
- return tsx;
3
+ exports.astro2tsx = void 0;
4
+ const sync_1 = require("@astrojs/compiler/sync");
5
+ function astro2tsx(content, fileName) {
6
+ try {
7
+ const tsx = (0, sync_1.convertToTSX)(content, { filename: fileName });
8
+ return tsx;
9
+ }
10
+ catch (e) {
11
+ console.error(`There was an error transforming ${fileName} to TSX. An empty file will be returned instead. Please create an issue: https://github.com/withastro/language-tools/issues\nError: ${e}.`);
12
+ return {
13
+ code: '',
14
+ map: {
15
+ file: fileName,
16
+ sources: [],
17
+ sourcesContent: [],
18
+ names: [],
19
+ mappings: '',
20
+ version: 0,
21
+ },
22
+ diagnostics: [],
23
+ };
24
+ }
7
25
  }
8
- exports.default = default_1;
26
+ exports.astro2tsx = astro2tsx;
@@ -1,4 +1,4 @@
1
- import type ts from 'typescript/lib/tsserverlibrary';
1
+ import type ts from 'typescript';
2
2
  import { CancellationToken, CompletionContext, Position, TextDocumentIdentifier, TextEdit } from 'vscode-languageserver';
3
3
  import type { ConfigManager } from '../../../core/config';
4
4
  import { AstroDocument } from '../../../core/documents';
@@ -1,3 +1,4 @@
1
+ import type ts from 'typescript';
1
2
  import { CancellationToken, DiagnosticSeverity } from 'vscode-languageserver';
2
3
  import { Diagnostic } from 'vscode-languageserver-types';
3
4
  import { AstroDocument } from '../../../core/documents';
@@ -125,6 +125,8 @@ class DiagnosticsProviderImpl {
125
125
  return vscode_languageserver_1.DiagnosticSeverity.Hint;
126
126
  case this.ts.DiagnosticCategory.Message:
127
127
  return vscode_languageserver_1.DiagnosticSeverity.Information;
128
+ default:
129
+ return vscode_languageserver_1.DiagnosticSeverity.Error;
128
130
  }
129
131
  }
130
132
  }
@@ -106,6 +106,6 @@ class SignatureHelpProviderImpl {
106
106
  };
107
107
  }
108
108
  }
109
- exports.SignatureHelpProviderImpl = SignatureHelpProviderImpl;
110
109
  SignatureHelpProviderImpl.triggerCharacters = ['(', ',', '<'];
111
110
  SignatureHelpProviderImpl.retriggerCharacters = [')'];
111
+ exports.SignatureHelpProviderImpl = SignatureHelpProviderImpl;
@@ -1,3 +1,4 @@
1
+ import type ts from 'typescript';
1
2
  import type { TextDocumentContentChangeEvent } from 'vscode-languageserver';
2
3
  import type { ConfigManager } from '../../core/config';
3
4
  import type { AstroDocument } from '../../core/documents';
@@ -1,3 +1,4 @@
1
+ import type ts from 'typescript';
1
2
  import type { ResolvedModule } from 'typescript';
2
3
  import type { DocumentSnapshot } from './snapshots/DocumentSnapshot';
3
4
  /**
@@ -12,7 +13,7 @@ import type { DocumentSnapshot } from './snapshots/DocumentSnapshot';
12
13
  * @param getSnapshot A function which returns a (in case of astro file fully preprocessed) typescript/javascript snapshot
13
14
  * @param compilerOptions The typescript compiler options
14
15
  */
15
- export declare function createAstroModuleLoader(getSnapshot: (fileName: string) => DocumentSnapshot, compilerOptions: ts.CompilerOptions, ts: typeof import('typescript/lib/tsserverlibrary')): {
16
+ export declare function createAstroModuleLoader(getSnapshot: (fileName: string) => DocumentSnapshot, compilerOptions: ts.CompilerOptions, ts: typeof import('typescript/lib/tsserverlibrary'), tsResolveModuleName?: typeof ts.resolveModuleName): {
16
17
  fileExists: (path: string) => boolean;
17
18
  readFile: (path: string, encoding?: string | undefined) => string | undefined;
18
19
  readDirectory: (path: string, extensions?: readonly string[] | undefined, exclude?: readonly string[] | undefined, include?: readonly string[] | undefined, depth?: number | undefined) => string[];
@@ -98,8 +98,11 @@ class ImpliedNodeFormatResolver {
98
98
  * @param getSnapshot A function which returns a (in case of astro file fully preprocessed) typescript/javascript snapshot
99
99
  * @param compilerOptions The typescript compiler options
100
100
  */
101
- function createAstroModuleLoader(getSnapshot, compilerOptions, ts) {
101
+ function createAstroModuleLoader(getSnapshot, compilerOptions, ts,
102
+ /* For tests */
103
+ tsResolveModuleName) {
102
104
  const astroSys = (0, astro_sys_1.createAstroSys)(getSnapshot, ts);
105
+ const tsResolver = tsResolveModuleName ? tsResolveModuleName : ts.resolveModuleName;
103
106
  const moduleCache = new ModuleResolutionCache();
104
107
  const impliedNodeFormatResolver = new ImpliedNodeFormatResolver(ts);
105
108
  return {
@@ -131,11 +134,11 @@ function createAstroModuleLoader(getSnapshot, compilerOptions, ts) {
131
134
  // Delegate to the TS resolver first.
132
135
  // If that does not bring up anything, try the Astro Module loader
133
136
  // which is able to deal with .astro and other frameworks files.
134
- const tsResolvedModule = ts.resolveModuleName(name, containingFile, compilerOptions, ts.sys, undefined, undefined, mode).resolvedModule;
137
+ const tsResolvedModule = tsResolver(name, containingFile, compilerOptions, ts.sys, undefined, undefined, mode).resolvedModule;
135
138
  if (tsResolvedModule && !(0, utils_2.isVirtualFilePath)(tsResolvedModule.resolvedFileName)) {
136
139
  return tsResolvedModule;
137
140
  }
138
- const astroResolvedModule = ts.resolveModuleName(name, containingFile, compilerOptions, astroSys, undefined, undefined, mode).resolvedModule;
141
+ const astroResolvedModule = tsResolver(name, containingFile, compilerOptions, astroSys, undefined, undefined, mode).resolvedModule;
139
142
  if (!astroResolvedModule || !(0, utils_2.isVirtualFilePath)(astroResolvedModule.resolvedFileName)) {
140
143
  return astroResolvedModule;
141
144
  }
@@ -1,3 +1,7 @@
1
+ /**
2
+ * adopted from https://github.com/microsoft/vscode/blob/10722887b8629f90cc38ee7d90d54e8246dc895f/extensions/typescript-language-features/src/utils/previewer.ts
3
+ */
4
+ import type ts from 'typescript';
1
5
  export declare function getTagDocumentation(tag: ts.JSDocTagInfo, ts: typeof import('typescript/lib/tsserverlibrary')): string | undefined;
2
6
  export declare function plain(parts: ts.SymbolDisplayPart[] | string, ts: typeof import('typescript/lib/tsserverlibrary')): string;
3
7
  export declare function getMarkdownDocumentation(documentation: ts.SymbolDisplayPart[] | undefined, tags: ts.JSDocTagInfo[] | undefined, ts: typeof import('typescript/lib/tsserverlibrary')): string;
@@ -5,9 +5,6 @@
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.getMarkdownDocumentation = exports.plain = exports.getTagDocumentation = void 0;
8
- /**
9
- * adopted from https://github.com/microsoft/vscode/blob/10722887b8629f90cc38ee7d90d54e8246dc895f/extensions/typescript-language-features/src/utils/previewer.ts
10
- */
11
8
  const utils_1 = require("../../utils");
12
9
  function replaceLinks(text) {
13
10
  return (text
@@ -1,5 +1,6 @@
1
1
  import { DiagnosticMessage } from '@astrojs/compiler/types';
2
2
  import { EncodedSourceMap, TraceMap } from '@jridgewell/trace-mapping';
3
+ import type ts from 'typescript';
3
4
  import { Position, TextDocumentContentChangeEvent } from 'vscode-languageserver';
4
5
  import { AstroDocument, DocumentMapper, FragmentMapper, IdentityMapper, SourceMapDocumentMapper, TagInformation } from '../../../core/documents';
5
6
  export interface DocumentSnapshot extends ts.IScriptSnapshot, DocumentMapper {
@@ -1,18 +1,15 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.classNameFromFilename = exports.createFromFrameworkFilePath = exports.createFromAstroFilePath = exports.createFromTSFilePath = exports.createFromNonAstroFilePath = exports.createFromFilePath = exports.createFromDocument = void 0;
7
4
  const vscode_uri_1 = require("vscode-uri");
8
5
  const importPackage_1 = require("../../../importPackage");
9
6
  const utils_1 = require("../../../utils");
10
- const astro2tsx_1 = __importDefault(require("../astro2tsx"));
7
+ const astro2tsx_1 = require("../astro2tsx");
11
8
  const utils_2 = require("../utils");
12
9
  const DocumentSnapshot_1 = require("./DocumentSnapshot");
13
10
  // Utilities to create Snapshots from different contexts
14
11
  function createFromDocument(document, ts) {
15
- const { code, map, diagnostics } = (0, astro2tsx_1.default)(document.getText(), document.getURL());
12
+ const { code, map, diagnostics } = (0, astro2tsx_1.astro2tsx)(document.getText(), document.getURL());
16
13
  const sourceMap = map;
17
14
  return new DocumentSnapshot_1.AstroSnapshot(document, code, sourceMap, ts.ScriptKind.TSX, diagnostics);
18
15
  }
@@ -1,3 +1,4 @@
1
+ import type ts from 'typescript';
1
2
  import type { Node } from 'vscode-html-languageservice';
2
3
  import { CompletionItemKind, Position, Range, SemanticTokensLegend, SymbolKind } from 'vscode-languageserver';
3
4
  import { AstroDocument, TagInformation } from '../../core/documents';
@@ -42,8 +43,8 @@ export declare function convertToLocationRange(defDoc: DocumentSnapshot, textSpa
42
43
  export declare function ensureFrontmatterInsert(resultRange: Range, document: AstroDocument): Range;
43
44
  export declare function checkEndOfFileCodeInsert(resultRange: Range, document: AstroDocument): Range;
44
45
  export declare function removeAstroComponentSuffix(name: string): string;
45
- export declare type FrameworkExt = 'astro' | 'vue' | 'jsx' | 'tsx' | 'svelte';
46
- declare type FrameworkVirtualExt = 'ts' | 'tsx';
46
+ export type FrameworkExt = 'astro' | 'vue' | 'jsx' | 'tsx' | 'svelte';
47
+ type FrameworkVirtualExt = 'ts' | 'tsx';
47
48
  export declare function getFrameworkFromFilePath(filePath: string): FrameworkExt;
48
49
  export declare function isVirtualFrameworkFilePath(ext: FrameworkExt, virtualExt: FrameworkVirtualExt, filePath: string): boolean;
49
50
  export declare function isAstroFilePath(filePath: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/language-server",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "author": "withastro",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -19,13 +19,12 @@
19
19
  "types"
20
20
  ],
21
21
  "dependencies": {
22
- "@astrojs/compiler": "^1.3.2",
22
+ "@astrojs/compiler": "^1.4.1",
23
23
  "@jridgewell/trace-mapping": "^0.3.14",
24
24
  "@vscode/emmet-helper": "^2.8.4",
25
25
  "events": "^3.3.0",
26
26
  "prettier": "^2.8.8",
27
27
  "prettier-plugin-astro": "^0.8.0",
28
- "synckit": "^0.8.4",
29
28
  "vscode-css-languageservice": "^6.2.1",
30
29
  "vscode-html-languageservice": "^5.0.0",
31
30
  "vscode-languageserver": "^8.0.1",
@@ -50,7 +49,7 @@
50
49
  "sinon": "^13.0.1",
51
50
  "svelte": "^3.49.0",
52
51
  "ts-node": "^10.7.0",
53
- "typescript": "~4.8.2",
52
+ "typescript": "~5.0.2",
54
53
  "vue": "^3.2.37"
55
54
  },
56
55
  "scripts": {
@@ -1,7 +0,0 @@
1
- import type { TSXResult } from '@astrojs/compiler/types';
2
- /**
3
- * Parse code by `@astrojs/compiler`
4
- */
5
- export declare function convertToTSX(source: string, options: {
6
- filename: string;
7
- }): TSXResult;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertToTSX = void 0;
4
- const synckit_1 = require("synckit");
5
- const convertToTSXSync = (0, synckit_1.createSyncFn)(require.resolve('./TSXWorker'));
6
- /**
7
- * Parse code by `@astrojs/compiler`
8
- */
9
- function convertToTSX(source, options) {
10
- return convertToTSXSync(source, options);
11
- }
12
- exports.convertToTSX = convertToTSX;
@@ -1 +0,0 @@
1
- export {};
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const synckit_1 = require("synckit");
4
- const dynamicImport = new Function('m', 'return import(m)');
5
- (0, synckit_1.runAsWorker)(async (source, options) => {
6
- const { convertToTSX } = await dynamicImport('@astrojs/compiler');
7
- const result = convertToTSX(source, options);
8
- return result;
9
- });