Skip to content

Commit

Permalink
feat(configuration): show error when schema.json not found
Browse files Browse the repository at this point in the history
  • Loading branch information
chemzqm committed Dec 7, 2018
1 parent b4222e7 commit 968ea74
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/__tests__/modules/configurations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ describe('Configurations', () => {
it('should load default configurations', () => {
let conf = new Configurations()
expect(conf.defaults.contents.coc).toBeDefined()
let c = conf.getConfiguration('languageserver')
expect(c).toEqual({})
conf.dispose()
})

Expand Down
6 changes: 5 additions & 1 deletion src/configuration/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { equals } from '../util/object'
import fs from 'fs'
import Uri from 'vscode-uri'
import path from 'path'
import { connect } from 'net'
const isPkg = process.hasOwnProperty('pkg')

export type ShowError = (errors: ErrorItem[]) => void
Expand Down Expand Up @@ -213,7 +214,10 @@ export function getConfigurationValue<T>(
export function loadDefaultConfigurations(): IConfigurationModel {
let root = isPkg ? path.resolve(process.execPath, '../..') : path.resolve(__dirname, '../..')
let file = path.join(root, 'data/schema.json')
if (!fs.existsSync(file)) return { contents: {} }
if (!fs.existsSync(file)) {
console.error('schema.json not found, reinstall coc.nvim to fix this!')
return { contents: {} }
}
let content = fs.readFileSync(file, 'utf8')
let { properties } = JSON.parse(content)
let config = {}
Expand Down
2 changes: 1 addition & 1 deletion src/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class ServiceManager extends EventEmitter implements Disposable {

private createCustomServices(): void {
let base = 'languageserver'
let lspConfig = workspace.getConfiguration().get<{ string: LanguageServerConfig }>(base)
let lspConfig = workspace.getConfiguration().get<{ string: LanguageServerConfig }>(base, {})
for (let key of Object.keys(lspConfig)) {
let config: LanguageServerConfig = lspConfig[key]
let id = `${base}.${key}`
Expand Down

0 comments on commit 968ea74

Please sign in to comment.