Skip to content

Commit

Permalink
Load main.ts to initialize lw before test
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Yu committed Nov 26, 2023
1 parent 94e18f7 commit 85f3b1b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/completion/completer/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { FileCache } from '../../types'
import type { ICompletionItem, IProvider, IProviderArgs } from '../latex'
import { CmdEnvSuggestion, splitSignatureString, filterNonLetterSuggestions, filterArgumentHint } from './completerutils'


const logger = lw.log('Intelli', 'Environment')

export type EnvType = {
Expand Down
19 changes: 13 additions & 6 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from 'vscode'
import * as fs from 'fs'
import * as path from 'path'
import { lw } from '../lw'

const LOG_PANEL = vscode.window.createOutputChannel('LaTeX Workshop')
const COMPILER_PANEL = vscode.window.createOutputChannel('LaTeX Compiler')
Expand Down Expand Up @@ -233,14 +234,20 @@ type PackageJSON = {
}
}

const defaultConf: Configs = (JSON.parse(fs.readFileSync(path.resolve(__dirname, '../../../../package.json')).toString()) as PackageJSON).contributes.configuration.properties

const relatedConf = [
'editor.acceptSuggestionOnEnter',
]

let defaultConfig: Configs | undefined = undefined
function getDefaultConfig() {
if (defaultConfig === undefined) {
defaultConfig = (JSON.parse(fs.readFileSync(path.resolve(lw.extensionRoot, 'package.json')).toString()) as PackageJSON).contributes.configuration.properties
}
return defaultConfig
}

function logConfig() {
const logConfigs = [...Object.keys(defaultConf), ...relatedConf]
const logConfigs = [...Object.keys(getDefaultConfig()), ...relatedConf]
const workspaceFolders = vscode.workspace.workspaceFolders || [undefined]
for (const workspace of workspaceFolders) {
const configuration = vscode.workspace.getConfiguration(undefined, workspace)
Expand All @@ -255,7 +262,7 @@ function logConfig() {
}

function logDeprecatedConfig() {
const deprecatedConfigs = Object.entries(defaultConf)
const deprecatedConfigs = Object.entries(getDefaultConfig())
.filter(([_, value]) => value.deprecationMessage)
.map(([config, _]) => config.split('.').slice(1).join('.'))
const workspaceFolders = vscode.workspace.workspaceFolders || [undefined]
Expand All @@ -266,14 +273,14 @@ function logDeprecatedConfig() {
const configValue = configuration.get(config)
if (JSON.stringify(defaultValue) !== JSON.stringify(configValue)) {
logTagless(`Deprecated config ${config} with default value ${JSON.stringify(defaultValue)} is set to ${JSON.stringify(configValue)} at ${workspace?.uri.toString(true)} .`)
void vscode.window.showWarningMessage(`Config "${config}" is deprecated. ${defaultConf[config].deprecationMessage}`)
void vscode.window.showWarningMessage(`Config "${config}" is deprecated. ${getDefaultConfig()[config].deprecationMessage}`)
}
})
}
}

function logConfigChange(ev: vscode.ConfigurationChangeEvent) {
const logConfigs = [...Object.keys(defaultConf), ...relatedConf]
const logConfigs = [...Object.keys(getDefaultConfig()), ...relatedConf]
const workspaceFolders = vscode.workspace.workspaceFolders || [undefined]
for (const workspace of workspaceFolders) {
logConfigs.forEach(config => {
Expand Down
15 changes: 7 additions & 8 deletions test/suites/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@ export function run(): Promise<void> {
})

return new Promise((resolve, reject) => {
try {
glob.sync('**/**.test.js', { cwd: __dirname })
.sort()
.forEach(f => mocha.addFile(path.resolve(__dirname, f)))
// Run the mocha test
glob.sync('**/**.test.js', { cwd: __dirname })
.sort()
.forEach(f => mocha.addFile(path.resolve(__dirname, f)))
// Run the mocha test
import('../../src/main').then(() => {
mocha.run(failures => {
if (failures > 0) {
reject(new Error(`${failures} tests failed.`))
} else {
resolve()
}
})
}
catch (error) {
}).catch(error => {
console.error(error)
return reject(error)
}
})
})
}
4 changes: 2 additions & 2 deletions test/suites/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import * as path from 'path'
import * as fs from 'fs'
import { glob } from 'glob'
import * as os from 'os'
import {ok, strictEqual} from 'assert'
import { ok, strictEqual } from 'assert'
import { lw } from '../../src/lw'
import { log as logModule } from '../../src/utils/logger'
import type { EventArgs, Events } from '../../src/core/event'

let testIndex = 0
const logger = lw.log('Test')
const logger = logModule.getLogger('Test')

function getFixture() {
if (vscode.workspace.workspaceFile) {
Expand Down

0 comments on commit 85f3b1b

Please sign in to comment.