Skip to content

Commit

Permalink
feat: vls checker extends Checker
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Jul 17, 2021
1 parent 8ba0641 commit 782f0c9
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 153 deletions.
83 changes: 4 additions & 79 deletions packages/checker-vls/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,9 @@
import {
CreateDiagnostic,
createScript,
ServeAndBuildChecker,
SharedConfig,
} from 'vite-plugin-checker'
import { isMainThread, parentPort } from 'worker_threads'
import * as commander from 'commander'

import { DiagnosticOptions, diagnostics } from './commands/diagnostics'

import type { ConfigEnv } from 'vite'

export const createDiagnostic: CreateDiagnostic = (userOptions = {}) => {
let overlay = true // Vite defaults to true

return {
config: ({ hmr }) => {
const viteOverlay = !(typeof hmr === 'object' && hmr.overlay === false)

if (userOptions.overlay === false || !viteOverlay) {
overlay = false
}
},
async configureServer({ root }) {
const workDir: string = userOptions.root ?? root
const errorCallback: DiagnosticOptions['errorCallback'] = (diagnostics, overlayErr) => {
if (!overlay) return
if (!overlayErr) return

parentPort?.postMessage({
type: 'ERROR',
payload: {
type: 'error',
err: overlayErr,
},
})
}

await diagnostics(workDir, 'WARN', { watch: true, errorCallback, verbose: false })
},
}
}

const { mainScript, workerScript } = createScript<{ vls: VlsConfig }>({
absFilename: __filename,
buildBin: ['vite-plugin-checker-vls', ['diagnostics']],
serverChecker: { createDiagnostic },
})!

if (isMainThread) {
const configCurryFn = (vlsConfig: VlsConfig) => {
return (sharedConfig: SharedConfig, env: ConfigEnv) => {
const createChecker = mainScript()
return createChecker({ vls: vlsConfig, ...sharedConfig }, env)
}
}

module.exports.VlsChecker = configCurryFn
module.exports.createServeAndBuild = configCurryFn
} else {
workerScript()
}

type VlsConfig = Partial<{
// TODO: support VLS config
}>

declare const VlsChecker: (
options?: VlsConfig
) => (config: VlsConfig & SharedConfig) => ServeAndBuildChecker

export { VlsChecker }
export type { VlsConfig }

import commander from 'commander'

export * as vscodeLanguageserverProtocol from 'vscode-languageserver-protocol'
export * as vscodeUri from 'vscode-uri'
export { commander }
export * as chokidar from 'chokidar'
export * as vls from 'vls'
export { commander }

export * as vscodeLanguageserverNode from 'vscode-languageserver/node'
export * as vscodeLanguageserverProtocol from 'vscode-languageserver-protocol'
export * as vscodeLanguageserverTextdocument from 'vscode-languageserver-textdocument'
export * as vscodeUri from 'vscode-uri'
73 changes: 73 additions & 0 deletions packages/checker-vls/src/main_backup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import {
CreateDiagnostic,
createScript,
ServeAndBuildChecker,
SharedConfig,
} from 'vite-plugin-checker'
import { isMainThread, parentPort } from 'worker_threads'

import { DiagnosticOptions, diagnostics } from './commands/diagnostics'

import type { ConfigEnv } from 'vite'

export const createDiagnostic: CreateDiagnostic = (userOptions = {}) => {
let overlay = true // Vite defaults to true

return {
config: ({ hmr }) => {
const viteOverlay = !(typeof hmr === 'object' && hmr.overlay === false)

if (userOptions.overlay === false || !viteOverlay) {
overlay = false
}
},
async configureServer({ root }) {
const workDir: string = userOptions.root ?? root
const errorCallback: DiagnosticOptions['errorCallback'] = (diagnostics, overlayErr) => {
if (!overlay) return
if (!overlayErr) return

parentPort?.postMessage({
type: 'ERROR',
payload: {
type: 'error',
err: overlayErr,
},
})
}

await diagnostics(workDir, 'WARN', { watch: true, errorCallback, verbose: false })
},
}
}

const { mainScript, workerScript } = createScript<{ vls: VlsConfig }>({
absFilename: __filename,
buildBin: ['vite-plugin-checker-vls', ['diagnostics']],
serverChecker: { createDiagnostic },
})!

if (isMainThread) {
const configCurryFn = (vlsConfig: VlsConfig) => {
return (sharedConfig: SharedConfig, env: ConfigEnv) => {
const createChecker = mainScript()
return createChecker({ vls: vlsConfig, ...sharedConfig }, env)
}
}

module.exports.VlsChecker = configCurryFn
module.exports.createServeAndBuild = configCurryFn
} else {
workerScript()
}

type VlsConfig = Partial<{
// TODO: support VLS config
}>

declare const VlsChecker: (
options?: VlsConfig
) => (config: VlsConfig & SharedConfig) => ServeAndBuildChecker

export { VlsChecker }
export type { VlsConfig }
121 changes: 61 additions & 60 deletions packages/vite-plugin-checker/src/checkers/vls2/main.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,74 @@
import {
CreateDiagnostic,
createScript,
ServeAndBuildChecker,
SharedConfig,
} from 'vite-plugin-checker'
import { isMainThread, parentPort } from 'worker_threads'
// import {
// CreateDiagnostic,
// createScript,
// ServeAndBuildChecker,
// SharedConfig,
// } from 'vite-plugin-checker'
// import { isMainThread, parentPort } from 'worker_threads'

import { DiagnosticOptions, diagnostics } from './commands/diagnostics'
// import { DiagnosticOptions, diagnostics } from './commands/diagnostics'

import type { ConfigEnv } from 'vite'
// import type { ConfigEnv } from 'vite'

export const createDiagnostic: CreateDiagnostic = (userOptions = {}) => {
let overlay = true // Vite defaults to true
// export const createDiagnostic: CreateDiagnostic = (userOptions = {}) => {
// let overlay = true // Vite defaults to true

return {
config: ({ hmr }) => {
const viteOverlay = !(typeof hmr === 'object' && hmr.overlay === false)
// return {
// config: ({ hmr }) => {
// const viteOverlay = !(typeof hmr === 'object' && hmr.overlay === false)

if (userOptions.overlay === false || !viteOverlay) {
overlay = false
}
},
async configureServer({ root }) {
const workDir: string = userOptions.root ?? root
const errorCallback: DiagnosticOptions['errorCallback'] = (diagnostics, overlayErr) => {
if (!overlay) return
if (!overlayErr) return
// if (userOptions.overlay === false || !viteOverlay) {
// overlay = false
// }
// },
// async configureServer({ root }) {
// const workDir: string = userOptions.root ?? root
// const errorCallback: DiagnosticOptions['errorCallback'] = (diagnostics, overlayErr) => {
// if (!overlay) return
// if (!overlayErr) return

parentPort?.postMessage({
type: 'ERROR',
payload: {
type: 'error',
err: overlayErr,
},
})
}
// parentPort?.postMessage({
// type: 'ERROR',
// payload: {
// type: 'error',
// err: overlayErr,
// },
// })
// }

await diagnostics(workDir, 'WARN', { watch: true, errorCallback, verbose: false })
},
}
}
// await diagnostics(workDir, 'WARN', { watch: true, errorCallback, verbose: false })
// },
// }
// }

const { mainScript, workerScript } = createScript<{ vls: VlsConfig }>({
absFilename: __filename,
buildBin: ['vite-plugin-checker-vls', ['diagnostics']],
serverChecker: { createDiagnostic },
})!
// const { mainScript, workerScript } = createScript<{ vls: VlsConfig }>({
// absFilename: __filename,
// buildBin: ['vite-plugin-checker-vls', ['diagnostics']],
// serverChecker: { createDiagnostic },
// })!

if (isMainThread) {
const configCurryFn = (vlsConfig: VlsConfig) => {
return (sharedConfig: SharedConfig, env: ConfigEnv) => {
const createChecker = mainScript()
return createChecker({ vls: vlsConfig, ...sharedConfig }, env)
}
}
// if (isMainThread) {
// const configCurryFn = (vlsConfig: VlsConfig) => {
// return (sharedConfig: SharedConfig, env: ConfigEnv) => {
// const createChecker = mainScript()
// return createChecker({ vls: vlsConfig, ...sharedConfig }, env)
// }
// }

module.exports.VlsChecker = configCurryFn
module.exports.createServeAndBuild = configCurryFn
} else {
workerScript()
}
// module.exports.VlsChecker = configCurryFn
// module.exports.createServeAndBuild = configCurryFn
// } else {
// workerScript()
// }

type VlsConfig = Partial<{
// TODO: support VLS config
}>
// type VlsConfig = Partial<{
// // TODO: support VLS config
// }>

declare const VlsChecker: (
options?: VlsConfig
) => (config: VlsConfig & SharedConfig) => ServeAndBuildChecker
// declare const VlsChecker: (
// options?: VlsConfig
// ) => (config: VlsConfig & SharedConfig) => ServeAndBuildChecker

export { VlsChecker }
export type { VlsConfig }
// export { VlsChecker }
// export type { VlsConfig }
export {}
61 changes: 61 additions & 0 deletions packages/vite-plugin-checker/src/checkers/vls2/main2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { parentPort } from 'worker_threads'

import { Checker, CheckerAbility } from '../../Checker'
import { DiagnosticOptions, diagnostics } from './commands/diagnostics'

import type { CreateDiagnostic } from '../../types'

export const createDiagnostic: CreateDiagnostic = (userOptions = {}) => {
let overlay = true // Vite defaults to true

return {
config: ({ hmr }) => {
const viteOverlay = !(typeof hmr === 'object' && hmr.overlay === false)

if (userOptions.overlay === false || !viteOverlay) {
overlay = false
}
},
async configureServer({ root }) {
const workDir: string = userOptions.root ?? root
const errorCallback: DiagnosticOptions['errorCallback'] = (diagnostics, overlayErr) => {
if (!overlay) return
if (!overlayErr) return

parentPort?.postMessage({
type: 'ERROR',
payload: {
type: 'error',
err: overlayErr,
},
})
}

await diagnostics(workDir, 'WARN', { watch: true, errorCallback, verbose: false })
},
}
}

export class VlsChecker extends Checker implements CheckerAbility {
public constructor() {
super({
name: 'vls',
absFilePath: __filename,
buildBin: ['vite-plugin-checker-vls', ['diagnostics']],
createDiagnostic,
})
}

public sealConclusion() {}

public init() {
const createServeAndBuild = super.initMainThread()
module.exports.createServeAndBuild = createServeAndBuild

super.initWorkerThread()
}
}

const vlsChecker = new VlsChecker()
vlsChecker.prepare()
vlsChecker.init()
Loading

0 comments on commit 782f0c9

Please sign in to comment.