Skip to content

Commit

Permalink
some cleanup and file position fix in cli (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
znck committed Nov 1, 2022
1 parent e7bdf73 commit 0f374fb
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 465 deletions.
4 changes: 2 additions & 2 deletions packages/typecheck/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function formatLocation(
start: TS.server.protocol.Location,
): string {
const relativeFileName = convertToRelativePath(fileName)
const line = start.line + 1
const column = start.offset + 1
const line = start.line
const column = start.offset

let output = ''
output += chalk.cyan(relativeFileName)
Expand Down
6 changes: 1 addition & 5 deletions packages/typescript-plugin-vue/src/contracts/TypeScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import type { TS_LANGUAGE_SERVICE } from '../constants'
export { TypeScript }
export type TSLanguageService = TypeScript.LanguageService
export type TSLanguageServiceHost = TypeScript.LanguageServiceHost
export type TSProject = TypeScript.server.Project & {
getParsedCommandLine?(
fileName: string,
): TypeScript.ParsedCommandLine | undefined
}
export type TSProject = TypeScript.server.Project
export type TSServerHost = TypeScript.server.ServerHost
export interface ExtendedTSLanguageService extends TSLanguageService {
[TS_LANGUAGE_SERVICE](): TSLanguageService
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const watchers = new Map<
>()

export function createFilesystemProvider(
projectService: TypeScript.server.ProjectService,
serverHost: TypeScript.server.ServerHost,
projectService?: TypeScript.server.ProjectService,
): FilesystemProvider {
const logger = LoggerService.getLogger('virtualFs')

const fix = (fileName: string): void => {
const scriptInfo = projectService.getScriptInfo(fileName)
const scriptInfo = projectService?.getScriptInfo(fileName)
if (scriptInfo == null) return
overrideMethod(
scriptInfo,
Expand All @@ -42,15 +42,15 @@ export function createFilesystemProvider(
const fs: FilesystemProvider = {
exists(fileName) {
const result =
projectService.getScriptInfo(fileName) != null ||
projectService?.getScriptInfo(fileName) != null ||
serverHost.fileExists(fileName)

logger.debug(`${result ? 'Y' : 'N'} = exists(${fileName})`)

return result
},
read(fileName) {
const snapshot = projectService.getScriptInfo(fileName)?.getSnapshot()
const snapshot = projectService?.getScriptInfo(fileName)?.getSnapshot()
if (snapshot == null) return serverHost.readFile(fileName) ?? ''
return snapshot.getText(0, snapshot.getLength())
},
Expand Down
8 changes: 6 additions & 2 deletions packages/typescript-plugin-vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ console.log =
import 'reflect-metadata'

import { Telemetry } from '@vuedx/shared'
import * as Path from 'path'
import type { Modules, PluginCreateInfo, TS } from './interfaces'
import type { PluginConfig } from './managers/ConfigManager'
import { pluginManager } from './managers/PluginManager'
Expand All @@ -30,12 +29,17 @@ export default function init({ typescript }: Modules): TS.server.PluginModule {
{ typescriptVersion: typescript.versionMajorMinor },
)

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { resolve } = require('node:path') as {
resolve: typeof import('node:path').resolve
}

return {
create(info: PluginCreateInfo) {
return pluginManager.create({
...info,
typescript,
typesDir: Path.resolve(__dirname, '..', 'runtime'),
typesDir: resolve(__dirname, '..', 'runtime'),
})
},
getExternalFiles(project) {
Expand Down
Loading

0 comments on commit 0f374fb

Please sign in to comment.