Skip to content

Commit

Permalink
Let VTI load default VLS config. Fix #2274
Browse files Browse the repository at this point in the history
  • Loading branch information
octref committed Sep 21, 2020
1 parent 601f8b0 commit 51936f0
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### 0.28.0

- Let VTI load default VLS config. #2274.
- Make `prettier` default formatter for HTML as prettyhtml is no longer actively maintained. #2291.
- Load prettier plugin from VLS if not present in workspace folder. #2014.
- Cross file template type checking - check that components are passed props with the correct types. #1596 and #2294.
Expand Down
23 changes: 8 additions & 15 deletions vti/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { createConnection } from 'vscode-languageserver';
import { Duplex } from 'stream';
import { VLS } from 'vls';
import { params } from './initParams';
import { getInitParams } from './initParams';
import * as fs from 'fs';
import { URI } from 'vscode-uri';
import * as glob from 'glob';
Expand Down Expand Up @@ -51,6 +51,7 @@ async function prepareClientConnection(workspaceUri: URI) {
await vls.init(params);

console.log('Vetur initialized');
console.log('====================================');

return {
capabilities: vls.capabilities
Expand All @@ -61,12 +62,7 @@ async function prepareClientConnection(workspaceUri: URI) {
vls.listen();
clientConnection.listen();

const init: InitializeParams = {
rootPath: workspaceUri.fsPath,
rootUri: workspaceUri.toString(),
processId: process.pid,
...params
} as InitializeParams;
const init = getInitParams(workspaceUri);

await clientConnection.sendRequest(InitializeRequest.type, init);

Expand All @@ -83,12 +79,11 @@ async function getDiagnostics(workspaceUri: URI) {
return 0;
}

console.log('Getting diagnostics from:');
console.log(files);
console.log('');
console.log('Getting diagnostics from: ', files, '\n');

const absFilePaths = files.map(f => path.resolve(workspaceUri.fsPath, f));

console.log('');
let errCount = 0;

for (const absFilePath of absFilePaths) {
Expand All @@ -106,7 +101,6 @@ async function getDiagnostics(workspaceUri: URI) {
uri: URI.file(absFilePath).toString()
})) as Diagnostic[];
if (res.length > 0) {
console.log('');
console.log(`${chalk.green('File')} : ${chalk.green(absFilePath)}`);
res.forEach(d => {
/**
Expand All @@ -116,10 +110,10 @@ async function getDiagnostics(workspaceUri: URI) {
return;
}
if (d.severity === DiagnosticSeverity.Error) {
console.log(`${chalk.red('Error')}: ${d.message}`);
console.log(`${chalk.red('Error')}: ${d.message.trim()}`);
errCount++;
} else {
console.log(`${chalk.yellow('Warn')} : ${d.message}`);
console.log(`${chalk.yellow('Warn')} : ${d.message.trim()}`);
}
});
console.log('');
Expand All @@ -137,6 +131,7 @@ async function getDiagnostics(workspaceUri: URI) {

// vls diagnostics
if (myArgs.length > 0 && myArgs[0] === 'diagnostics') {
console.log('====================================');
console.log('Getting Vetur diagnostics');
let workspaceUri;

Expand All @@ -149,8 +144,6 @@ async function getDiagnostics(workspaceUri: URI) {
workspaceUri = URI.file(process.cwd());
}

console.log('');
console.log('====================================');
const errCount = await getDiagnostics(workspaceUri);
console.log('====================================');

Expand Down
120 changes: 105 additions & 15 deletions vti/src/initParams.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,108 @@
export const params = {
capabilities: {},
initializationOptions: {
config: {
vetur: {
validation: {
template: true,
style: false,
script: false,
templateProps: true
},
experimental: {
templateInterpolationService: true
import { InitializeParams } from 'vscode-languageserver-protocol';
import { URI } from 'vscode-uri';

export function getInitParams(workspaceUri: URI): InitializeParams {
const defaultVLSConfig = getDefaultVLSConfig();

defaultVLSConfig.vetur.validation = {
template: false,
style: false,
script: false,
interpolation: true,
templateProps: true
};
defaultVLSConfig.vetur.experimental = {
templateInterpolationService: true
};

const init: InitializeParams = {
rootPath: workspaceUri.fsPath,
rootUri: workspaceUri.toString(),
processId: process.pid,
capabilities: {},
initializationOptions: {
config: defaultVLSConfig
}
} as InitializeParams;

return init;
}

function getDefaultVLSConfig() {
return {
vetur: {
useWorkspaceDependencies: false,
validation: {
template: true,
templateProps: false,
interpolation: true,
style: true,
script: true
},
completion: {
autoImport: false,
tagCasing: 'kebab',
scaffoldSnippetSources: {
workspace: '💼',
user: '🗒️',
vetur: '✌'
}
},
grammar: {
customBlocks: {}
},
format: {
enable: true,
options: {
tabSize: 2,
useTabs: false
},
defaultFormatter: {},
defaultFormatterOptions: {},
scriptInitialIndent: false,
styleInitialIndent: false
},
trace: {
server: 'off'
},
dev: {
vlsPath: '',
vlsPort: -1,
logLevel: 'INFO'
},
experimental: {
templateInterpolationService: false
}
},
css: {},
html: {
suggest: {}
},
javascript: {
format: {}
},
typescript: {
tsdk: null,
format: {}
},
emmet: {},
stylusSupremacy: {}
};
}

function getExtraConfig() {
return {
vetur: {
validation: {
template: true,
templateProps: true,
interpolation: true,
style: false,
script: false
},
experimental: {
templateInterpolationService: false
}
}
}
};
};
}

0 comments on commit 51936f0

Please sign in to comment.