diff --git a/packages/language-server/package.json b/packages/language-server/package.json index 2963ffe11..d6a05f9e3 100644 --- a/packages/language-server/package.json +++ b/packages/language-server/package.json @@ -7,7 +7,8 @@ "exports": { "./package.json": "./package.json", ".": "./dist/src/index.js", - "./bin/server.js": "./bin/server.js" + "./bin/server.js": "./bin/server.js", + "./svelte-check": "./dist/src/svelte-check.js" }, "scripts": { "test": "cross-env TS_NODE_TRANSPILE_ONLY=true mocha --require ts-node/register \"test/**/*.test.ts\"", diff --git a/packages/language-server/src/svelte-check.ts b/packages/language-server/src/svelte-check.ts index 75a62b173..d051dc4d7 100644 --- a/packages/language-server/src/svelte-check.ts +++ b/packages/language-server/src/svelte-check.ts @@ -1,24 +1,25 @@ +import { groupBy } from 'lodash'; import { isAbsolute } from 'path'; import ts from 'typescript'; import { Diagnostic, Position, Range } from 'vscode-languageserver'; -import { WorkspaceFolder } from 'vscode-languageserver-protocol'; +import { TextDocumentContentChangeEvent, WorkspaceFolder } from 'vscode-languageserver-protocol'; import { Document, DocumentManager } from './lib/documents'; import { Logger } from './logger'; import { LSConfigManager } from './ls-config'; -import { - CSSPlugin, - LSAndTSDocResolver, - PluginHost, - SveltePlugin, - TypeScriptPlugin -} from './plugins'; +import { Plugin } from './plugins'; +import { CSSPlugin } from './plugins/css/CSSPlugin'; import { FileSystemProvider } from './plugins/css/FileSystemProvider'; import { createLanguageServices } from './plugins/css/service'; +import { PluginHost } from './plugins/PluginHost'; +import { SveltePlugin } from './plugins/svelte/SveltePlugin'; import { JSOrTSDocumentSnapshot } from './plugins/typescript/DocumentSnapshot'; +import { DiagnosticsProviderImpl } from './plugins/typescript/features/DiagnosticsProvider'; import { isInGeneratedCode } from './plugins/typescript/features/utils'; +import { LSAndTSDocResolver } from './plugins/typescript/LSAndTSDocResolver'; import { convertRange, getDiagnosticTag, mapSeverity } from './plugins/typescript/utils'; import { pathToUrl, urlToPath } from './utils'; -import { groupBy } from 'lodash'; + +export { offsetAt } from './lib/documents'; export type SvelteCheckDiagnosticSource = 'js' | 'css' | 'svelte'; @@ -95,12 +96,7 @@ export class SvelteCheck { } ); this.pluginHost.register( - new TypeScriptPlugin( - this.configManager, - this.lsAndTSDocResolver, - workspaceUris, - this.docManager - ) + new SvelteCheckTypeScriptPlugin(this.lsAndTSDocResolver, this.configManager) ); } @@ -354,3 +350,26 @@ export class SvelteCheck { return this.lsAndTSDocResolver.getTSService(tsconfigPath); } } + +export class SvelteCheckTypeScriptPlugin implements Plugin { + __name = 'ts'; + + constructor(lsAndTSDocResolver: LSAndTSDocResolver, lsConfigManager: LSConfigManager) { + this.lsAndTsDocResolver = lsAndTSDocResolver; + this.diagnosticsProvider = new DiagnosticsProviderImpl(lsAndTSDocResolver, lsConfigManager); + } + + private readonly diagnosticsProvider: DiagnosticsProviderImpl; + private readonly lsAndTsDocResolver: LSAndTSDocResolver; + + getDiagnostics(document: Document): Promise { + return this.diagnosticsProvider.getDiagnostics(document); + } + + async updateTsOrJsFile( + fileName: string, + changes: TextDocumentContentChangeEvent[] + ): Promise { + await this.lsAndTsDocResolver.updateExistingTsOrJsFile(fileName, changes); + } +} diff --git a/packages/svelte-check/package.json b/packages/svelte-check/package.json index b49d294a2..a48d8bc8b 100644 --- a/packages/svelte-check/package.json +++ b/packages/svelte-check/package.json @@ -55,9 +55,9 @@ "svelte": "^4.2.19", "svelte-language-server": "workspace:*", "typescript": "^5.5.2", - "vscode-languageserver": "8.0.2", - "vscode-languageserver-protocol": "3.17.2", - "vscode-languageserver-types": "3.17.2", + "vscode-languageserver": "9.0.1", + "vscode-languageserver-protocol": "3.17.5", + "vscode-languageserver-types": "3.17.5", "vscode-uri": "~3.0.0" } } diff --git a/packages/svelte-check/src/index.ts b/packages/svelte-check/src/index.ts index f2aeb79fb..b9044bf89 100644 --- a/packages/svelte-check/src/index.ts +++ b/packages/svelte-check/src/index.ts @@ -6,7 +6,7 @@ import { watch } from 'chokidar'; import * as fs from 'fs'; import { fdir } from 'fdir'; import * as path from 'path'; -import { SvelteCheck, SvelteCheckOptions } from 'svelte-language-server'; +import { SvelteCheck, SvelteCheckOptions } from 'svelte-language-server/svelte-check'; import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver-protocol'; import { URI } from 'vscode-uri'; import { parseOptions, SvelteCheckCliOptions } from './options'; diff --git a/packages/svelte-check/src/writers.ts b/packages/svelte-check/src/writers.ts index af1fd89d8..3152dbfaf 100644 --- a/packages/svelte-check/src/writers.ts +++ b/packages/svelte-check/src/writers.ts @@ -2,7 +2,7 @@ import pc from 'picocolors'; import { sep } from 'path'; import { Writable } from 'stream'; import { Diagnostic, DiagnosticSeverity } from 'vscode-languageserver-protocol'; -import { offsetAt } from 'svelte-language-server'; +import { offsetAt } from 'svelte-language-server/svelte-check'; export interface Writer { start: (workspaceDir: string) => void; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f7d19793f..0cee848bc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -165,14 +165,14 @@ importers: specifier: ^5.5.2 version: 5.5.2 vscode-languageserver: - specifier: 8.0.2 - version: 8.0.2 + specifier: 9.0.1 + version: 9.0.1 vscode-languageserver-protocol: - specifier: 3.17.2 - version: 3.17.2 + specifier: 3.17.5 + version: 3.17.5 vscode-languageserver-types: - specifier: 3.17.2 - version: 3.17.2 + specifier: 3.17.5 + version: 3.17.5 vscode-uri: specifier: ~3.0.0 version: 3.0.8 @@ -1299,10 +1299,6 @@ packages: vscode-html-languageservice@5.3.0: resolution: {integrity: sha512-C4Z3KsP5Ih+fjHpiBc5jxmvCl+4iEwvXegIrzu2F5pktbWvQaBT3YkVPk8N+QlSSMk8oCG6PKtZ/Sq2YHb5e8g==} - vscode-jsonrpc@8.0.2: - resolution: {integrity: sha512-RY7HwI/ydoC1Wwg4gJ3y6LpU9FJRZAUnTYMXthqhFXXu77ErDd/xkREpGuk4MyYkk4a+XDWAMqe0S3KkelYQEQ==} - engines: {node: '>=14.0.0'} - vscode-jsonrpc@8.2.0: resolution: {integrity: sha512-C+r0eKJUIfiDIfwJhria30+TYWPtuHJXHtI7J0YlOmKAo7ogxP20T0zxB7HZQIFhIyvoBPwWskjxrvAtfjyZfA==} engines: {node: '>=14.0.0'} @@ -1311,25 +1307,15 @@ packages: resolution: {integrity: sha512-JZiimVdvimEuHh5olxhxkht09m3JzUGwggb5eRUkzzJhZ2KjCN0nh55VfiED9oez9DyF8/fz1g1iBV3h+0Z2EA==} engines: {vscode: ^1.82.0} - vscode-languageserver-protocol@3.17.2: - resolution: {integrity: sha512-8kYisQ3z/SQ2kyjlNeQxbkkTNmVFoQCqkmGrzLH6A9ecPlgTbp3wDTnUNqaUxYr4vlAcloxx8zwy7G5WdguYNg==} - vscode-languageserver-protocol@3.17.5: resolution: {integrity: sha512-mb1bvRJN8SVznADSGWM9u/b07H7Ecg0I3OgXDuLdn307rl/J3A9YD6/eYOssqhecL27hK1IPZAsaqh00i/Jljg==} vscode-languageserver-textdocument@1.0.11: resolution: {integrity: sha512-X+8T3GoiwTVlJbicx/sIAF+yuJAqz8VvwJyoMVhwEMoEKE/fkDmrqUgDMyBECcM2A2frVZIUj5HI/ErRXCfOeA==} - vscode-languageserver-types@3.17.2: - resolution: {integrity: sha512-zHhCWatviizPIq9B7Vh9uvrH6x3sK8itC84HkamnBWoDFJtzBf7SWlpLCZUit72b3os45h6RWQNC9xHRDF8dRA==} - vscode-languageserver-types@3.17.5: resolution: {integrity: sha512-Ld1VelNuX9pdF39h2Hgaeb5hEZM2Z3jUrrMgWQAu82jMtZp7p3vJT3BzToKtZI7NgQssZje5o0zryOrhQvzQAg==} - vscode-languageserver@8.0.2: - resolution: {integrity: sha512-bpEt2ggPxKzsAOZlXmCJ50bV7VrxwCS5BI4+egUmure/oI/t4OlFzi/YNtVvY24A2UDOZAgwFGgnZPwqSJubkA==} - hasBin: true - vscode-languageserver@9.0.1: resolution: {integrity: sha512-woByF3PDpkHFUreUa7Hos7+pUWdeWMXRd26+ZX2A8cFx6v/JPTtd4/uN0/jB6XQHYaOlHbio03NTHCqrgG5n7g==} hasBin: true @@ -2375,8 +2361,6 @@ snapshots: vscode-languageserver-types: 3.17.5 vscode-uri: 3.0.8 - vscode-jsonrpc@8.0.2: {} - vscode-jsonrpc@8.2.0: {} vscode-languageclient@9.0.1: @@ -2385,11 +2369,6 @@ snapshots: semver: 7.5.1 vscode-languageserver-protocol: 3.17.5 - vscode-languageserver-protocol@3.17.2: - dependencies: - vscode-jsonrpc: 8.0.2 - vscode-languageserver-types: 3.17.2 - vscode-languageserver-protocol@3.17.5: dependencies: vscode-jsonrpc: 8.2.0 @@ -2397,14 +2376,8 @@ snapshots: vscode-languageserver-textdocument@1.0.11: {} - vscode-languageserver-types@3.17.2: {} - vscode-languageserver-types@3.17.5: {} - vscode-languageserver@8.0.2: - dependencies: - vscode-languageserver-protocol: 3.17.2 - vscode-languageserver@9.0.1: dependencies: vscode-languageserver-protocol: 3.17.5