@astrojs/ts-plugin
Advanced tools
Comparing version 1.0.7 to 1.0.8
# @astrojs/ts-plugin | ||
## 1.0.8 | ||
### Patch Changes | ||
- 170a193: Update dependencies | ||
## 1.0.7 | ||
@@ -4,0 +10,0 @@ |
{ | ||
"name": "@astrojs/ts-plugin", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "A TypeScript Plugin providing Astro intellisense", | ||
"main": "dist/index.js", | ||
"type": "commonjs", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/withastro/language-tools", | ||
"directory": "packages/ts-plugin" | ||
}, | ||
"keywords": [ | ||
@@ -16,27 +21,21 @@ "astro", | ||
"dependencies": { | ||
"@astrojs/compiler": "^1.4.2", | ||
"@jridgewell/trace-mapping": "^0.3.15" | ||
"@astrojs/compiler": "^1.5.1", | ||
"@jridgewell/trace-mapping": "^0.3.18" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.3.0", | ||
"@types/mocha": "^9.1.1", | ||
"@types/node": "^16.11.58", | ||
"@types/vscode": "^1.67.0", | ||
"@vscode/test-electron": "^2.1.5", | ||
"astro-scripts": "*", | ||
"chai": "^4.3.6", | ||
"@types/chai": "^4.3.5", | ||
"@types/mocha": "^10.0.1", | ||
"@types/node": "^16.18.26", | ||
"@types/vscode": "1.67.0", | ||
"@vscode/test-electron": "^2.3.2", | ||
"chai": "^4.3.7", | ||
"glob": "^8.0.3", | ||
"mocha": "^9.2.2", | ||
"typescript": "~5.0.2" | ||
"mocha": "^10.2.0", | ||
"typescript": "~5.1.3" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/withastro/language-tools", | ||
"directory": "packages/ts-plugin" | ||
}, | ||
"scripts": { | ||
"build": "astro-scripts build \"src/**/*.ts\"", | ||
"dev": "astro-scripts dev \"src/**/*.ts\"", | ||
"build": "tsc", | ||
"dev": "tsc --watch", | ||
"test": "node ./test/runTest.js" | ||
} | ||
} |
@@ -142,3 +142,5 @@ import { EncodedSourceMap, originalPositionFor, TraceMap } from '@jridgewell/trace-mapping'; | ||
const nextLineOffset = | ||
position.line + 1 < lineOffsets.length ? lineOffsets[position.line + 1] : this.astroCode.length; | ||
position.line + 1 < lineOffsets.length | ||
? lineOffsets[position.line + 1] | ||
: this.astroCode.length; | ||
@@ -205,3 +207,7 @@ return this.clamp(nextLineOffset, lineOffset, lineOffset + position.character); | ||
constructor(private typescript: typeof ts, private projectService: ts.server.ProjectService, private logger: Logger) { | ||
constructor( | ||
private typescript: typeof ts, | ||
private projectService: ts.server.ProjectService, | ||
private logger: Logger | ||
) { | ||
this.patchProjectServiceReadFile(); | ||
@@ -236,3 +242,6 @@ } | ||
if (!snapshot) { | ||
this.logger.log('Astro snapshot was not found after trying to load script snapshot for', fileName); | ||
this.logger.log( | ||
'Astro snapshot was not found after trying to load script snapshot for', | ||
fileName | ||
); | ||
return; // should never get here | ||
@@ -239,0 +248,0 @@ } |
@@ -8,3 +8,6 @@ import type ts from 'typescript/lib/tsserverlibrary'; | ||
*/ | ||
export function createAstroSys(logger: Logger, typescript: typeof import('typescript/lib/tsserverlibrary')) { | ||
export function createAstroSys( | ||
logger: Logger, | ||
typescript: typeof import('typescript/lib/tsserverlibrary') | ||
) { | ||
const astroSys: ts.System = { | ||
@@ -11,0 +14,0 @@ ...typescript.sys, |
@@ -6,4 +6,3 @@ import { convertToTSX } from '@astrojs/compiler/sync'; | ||
const tsx = convertToTSX(content, { filename: fileName }); | ||
return tsx; | ||
} |
@@ -14,3 +14,5 @@ import type ts from 'typescript/lib/tsserverlibrary'; | ||
const logger = new Logger(info.project.projectService.logger); | ||
const parsedCommandLine = info.languageServiceHost.getParsedCommandLine?.(getConfigPathForProject(info.project)); | ||
const parsedCommandLine = info.languageServiceHost.getParsedCommandLine?.( | ||
getConfigPathForProject(info.project) | ||
); | ||
@@ -28,3 +30,7 @@ if (!isAstroProject(info.project, parsedCommandLine)) { | ||
const snapshotManager = new AstroSnapshotManager(modules.typescript, info.project.projectService, logger); | ||
const snapshotManager = new AstroSnapshotManager( | ||
modules.typescript, | ||
info.project.projectService, | ||
logger | ||
); | ||
if (parsedCommandLine) { | ||
@@ -40,3 +46,9 @@ new ProjectAstroFilesManager( | ||
patchModuleLoader(logger, snapshotManager, modules.typescript, info.languageServiceHost, info.project); | ||
patchModuleLoader( | ||
logger, | ||
snapshotManager, | ||
modules.typescript, | ||
info.languageServiceHost, | ||
info.project | ||
); | ||
return decorateLanguageService(info.languageService, snapshotManager, ts, logger); | ||
@@ -49,3 +61,6 @@ } | ||
function isAstroProject(project: ts.server.Project, parsedCommandLine: ts.ParsedCommandLine | undefined) { | ||
function isAstroProject( | ||
project: ts.server.Project, | ||
parsedCommandLine: ts.ParsedCommandLine | undefined | ||
) { | ||
if (parsedCommandLine) { | ||
@@ -52,0 +67,0 @@ const astroFiles = readProjectAstroFilesFromFs(ts, project, parsedCommandLine); |
@@ -29,3 +29,11 @@ import type ts from 'typescript/lib/tsserverlibrary'; | ||
const getCompletionEntryDetails = ls.getCompletionEntryDetails; | ||
ls.getCompletionEntryDetails = (fileName, position, entryName, formatOptions, source, preferences, data) => { | ||
ls.getCompletionEntryDetails = ( | ||
fileName, | ||
position, | ||
entryName, | ||
formatOptions, | ||
source, | ||
preferences, | ||
data | ||
) => { | ||
if (!isAstroFilePath(source || '')) { | ||
@@ -32,0 +40,0 @@ const details = getCompletionEntryDetails( |
@@ -5,3 +5,6 @@ import type ts from 'typescript/lib/tsserverlibrary'; | ||
export function decorateGetDefinition(ls: ts.LanguageService, snapshotManager: AstroSnapshotManager): void { | ||
export function decorateGetDefinition( | ||
ls: ts.LanguageService, | ||
snapshotManager: AstroSnapshotManager | ||
): void { | ||
const getDefinitionAndBoundSpan = ls.getDefinitionAndBoundSpan; | ||
@@ -8,0 +11,0 @@ ls.getDefinitionAndBoundSpan = (fileName, position) => { |
@@ -39,3 +39,6 @@ import type ts from 'typescript/lib/tsserverlibrary'; | ||
diagnostics = diagnostics.map((diag) => { | ||
const message = typescript.flattenDiagnosticMessageText(diag.messageText, typescript.sys.newLine); | ||
const message = typescript.flattenDiagnosticMessageText( | ||
diag.messageText, | ||
typescript.sys.newLine | ||
); | ||
if ( | ||
@@ -42,0 +45,0 @@ diag.code === DiagnosticCodes.CANNOT_FIND_MODULE && |
@@ -5,3 +5,6 @@ import type ts from 'typescript/lib/tsserverlibrary'; | ||
export function decorateGetFileReferences(ls: ts.LanguageService, snapshotManager: AstroSnapshotManager): void { | ||
export function decorateGetFileReferences( | ||
ls: ts.LanguageService, | ||
snapshotManager: AstroSnapshotManager | ||
): void { | ||
const getFileReferences = ls.getFileReferences; | ||
@@ -8,0 +11,0 @@ ls.getFileReferences = (fileName) => { |
@@ -15,3 +15,7 @@ import type ts from 'typescript/lib/tsserverlibrary'; | ||
function _decorateFindReferences(ls: ts.LanguageService, snapshotManager: AstroSnapshotManager, logger: Logger) { | ||
function _decorateFindReferences( | ||
ls: ts.LanguageService, | ||
snapshotManager: AstroSnapshotManager, | ||
logger: Logger | ||
) { | ||
const findReferences = ls.findReferences; | ||
@@ -18,0 +22,0 @@ ls.findReferences = (fileName, position) => { |
@@ -5,3 +5,6 @@ import type ts from 'typescript/lib/tsserverlibrary'; | ||
export function decorateGetImplementation(ls: ts.LanguageService, snapshotManager: AstroSnapshotManager): void { | ||
export function decorateGetImplementation( | ||
ls: ts.LanguageService, | ||
snapshotManager: AstroSnapshotManager | ||
): void { | ||
const getImplementationAtPosition = ls.getImplementationAtPosition; | ||
@@ -8,0 +11,0 @@ ls.getImplementationAtPosition = (fileName, position) => { |
@@ -5,3 +5,6 @@ import type ts from 'typescript/lib/tsserverlibrary'; | ||
export function decorateLineColumnOffset(ls: ts.LanguageService, snapshotManager: AstroSnapshotManager) { | ||
export function decorateLineColumnOffset( | ||
ls: ts.LanguageService, | ||
snapshotManager: AstroSnapshotManager | ||
) { | ||
if (!ls.toLineColumnOffset) { | ||
@@ -8,0 +11,0 @@ return; |
@@ -6,5 +6,9 @@ import type ts from 'typescript/lib/tsserverlibrary'; | ||
export function decorateRename(ls: ts.LanguageService, snapshotManager: AstroSnapshotManager, logger: Logger): void { | ||
export function decorateRename( | ||
ls: ts.LanguageService, | ||
snapshotManager: AstroSnapshotManager, | ||
logger: Logger | ||
): void { | ||
const findRenameLocations = ls.findRenameLocations; | ||
ls.findRenameLocations = (fileName, position, findInStrings, findInComments, providePrefixAndSuffixTextForRename) => { | ||
ls.findRenameLocations = (fileName, position, findInStrings, findInComments, preferences) => { | ||
const renameLocations = findRenameLocations( | ||
@@ -15,3 +19,3 @@ fileName, | ||
findInComments, | ||
providePrefixAndSuffixTextForRename | ||
preferences as ts.UserPreferences | ||
); | ||
@@ -18,0 +22,0 @@ return renameLocations |
import type ts from 'typescript/lib/tsserverlibrary'; | ||
export class Logger { | ||
constructor(private tsLogService: ts.server.Logger, suppressNonAstroLogs = false, private logDebug = false) { | ||
constructor( | ||
private tsLogService: ts.server.Logger, | ||
suppressNonAstroLogs = false, | ||
private logDebug = false | ||
) { | ||
if (suppressNonAstroLogs) { | ||
@@ -6,0 +10,0 @@ const log = this.tsLogService.info.bind(this.tsLogService); |
@@ -23,3 +23,7 @@ import type ts from 'typescript/lib/tsserverlibrary'; | ||
*/ | ||
set(moduleName: string, containingFile: string, resolvedModule: ts.ResolvedModuleFull | undefined) { | ||
set( | ||
moduleName: string, | ||
containingFile: string, | ||
resolvedModule: ts.ResolvedModuleFull | undefined | ||
) { | ||
if (!resolvedModule) { | ||
@@ -103,4 +107,9 @@ return; | ||
const resolved = | ||
origResolveModuleNames?.(moduleNames, containingFile, reusedNames, redirectedReference, compilerOptions) || | ||
Array.from<undefined>(Array(moduleNames.length)); | ||
origResolveModuleNames?.( | ||
moduleNames, | ||
containingFile, | ||
reusedNames, | ||
redirectedReference, | ||
compilerOptions | ||
) || Array.from<undefined>(Array(moduleNames.length)); | ||
@@ -183,3 +192,6 @@ return resolved.map((moduleName, idx) => { | ||
const moduleName = moduleLiterals[idx].text; | ||
if (tsResolvedModule.resolvedModule || !ensureRealAstroFilePath(moduleName).endsWith('.astro')) { | ||
if ( | ||
tsResolvedModule.resolvedModule || | ||
!ensureRealAstroFilePath(moduleName).endsWith('.astro') | ||
) { | ||
return tsResolvedModule; | ||
@@ -192,3 +204,7 @@ } | ||
function resolveAstroModuleNameFromCache(moduleName: string, containingFile: string, options: ts.CompilerOptions) { | ||
function resolveAstroModuleNameFromCache( | ||
moduleName: string, | ||
containingFile: string, | ||
options: ts.CompilerOptions | ||
) { | ||
const cachedModule = moduleCache.get(moduleName, containingFile); | ||
@@ -195,0 +211,0 @@ if (cachedModule) { |
@@ -29,3 +29,5 @@ import type ts from 'typescript/lib/tsserverlibrary'; | ||
updateProjectConfig(serviceHost: ts.LanguageServiceHost) { | ||
const parsedCommandLine = serviceHost.getParsedCommandLine?.(getConfigPathForProject(this.project)); | ||
const parsedCommandLine = serviceHost.getParsedCommandLine?.( | ||
getConfigPathForProject(this.project) | ||
); | ||
@@ -53,3 +55,5 @@ if (!parsedCommandLine) { | ||
for (const directory in this.parsedCommandLine.wildcardDirectories) { | ||
if (!Object.prototype.hasOwnProperty.call(this.parsedCommandLine.wildcardDirectories, directory)) { | ||
if ( | ||
!Object.prototype.hasOwnProperty.call(this.parsedCommandLine.wildcardDirectories, directory) | ||
) { | ||
continue; | ||
@@ -82,3 +86,7 @@ } | ||
private updateProjectAstroFiles() { | ||
const fileNamesAfter = readProjectAstroFilesFromFs(this.typescript, this.project, this.parsedCommandLine); | ||
const fileNamesAfter = readProjectAstroFilesFromFs( | ||
this.typescript, | ||
this.project, | ||
this.parsedCommandLine | ||
); | ||
const removedFiles = new Set(...this.files); | ||
@@ -85,0 +93,0 @@ const newFiles = fileNamesAfter.filter((fileName) => { |
@@ -23,3 +23,5 @@ const path = require('path'); | ||
if (file.startsWith('vscode-')) { | ||
vsPath = downloadDirToExecutablePath(path.resolve(__dirname, '../../vscode/.vscode-test/', file)); | ||
vsPath = downloadDirToExecutablePath( | ||
path.resolve(__dirname, '../../vscode/.vscode-test/', file) | ||
); | ||
return; | ||
@@ -26,0 +28,0 @@ } |
@@ -18,3 +18,5 @@ const assert = require('assert'); | ||
} | ||
throw new Error(`TypeScript plugin never started or condition never resolved for command ${command}`); | ||
throw new Error( | ||
`TypeScript plugin never started or condition never resolved for command ${command}` | ||
); | ||
} | ||
@@ -30,3 +32,5 @@ | ||
test('can find references inside Astro files', async () => { | ||
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.join(__dirname, '../fixtures/script.ts'))); | ||
const doc = await vscode.workspace.openTextDocument( | ||
vscode.Uri.file(path.join(__dirname, '../fixtures/script.ts')) | ||
); | ||
@@ -44,3 +48,5 @@ const references = await waitForTS( | ||
test('can get completions for Astro components', async () => { | ||
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.join(__dirname, '../fixtures/script.ts'))); | ||
const doc = await vscode.workspace.openTextDocument( | ||
vscode.Uri.file(path.join(__dirname, '../fixtures/script.ts')) | ||
); | ||
@@ -60,3 +66,5 @@ const completions = await waitForTS( | ||
test('can get implementations inside Astro files', async () => { | ||
const doc = await vscode.workspace.openTextDocument(vscode.Uri.file(path.join(__dirname, '../fixtures/script.ts'))); | ||
const doc = await vscode.workspace.openTextDocument( | ||
vscode.Uri.file(path.join(__dirname, '../fixtures/script.ts')) | ||
); | ||
@@ -69,5 +77,7 @@ const implementations = await waitForTS( | ||
const hasAstroImplementation = implementations.some((impl) => impl.uri.path.includes('MyAstroComponent')); | ||
const hasAstroImplementation = implementations.some((impl) => | ||
impl.uri.path.includes('MyAstroComponent') | ||
); | ||
expect(hasAstroImplementation).to.be.true; | ||
}).timeout(12000); | ||
}); |
@@ -49,3 +49,7 @@ /* MIT License | ||
systemDefaultPlatform = | ||
process.arch === 'arm64' ? 'linux-arm64' : process.arch === 'arm' ? 'linux-armhf' : 'linux-x64'; | ||
process.arch === 'arm64' | ||
? 'linux-arm64' | ||
: process.arch === 'arm' | ||
? 'linux-armhf' | ||
: 'linux-x64'; | ||
} | ||
@@ -52,0 +56,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9
61772
1581