Skip to content

Commit

Permalink
Merge pull request vuejs#1634 from vuejs/vti
Browse files Browse the repository at this point in the history
Vti
  • Loading branch information
octref committed Jan 12, 2020
2 parents ad2490a + 17b3c6e commit d56ef88
Show file tree
Hide file tree
Showing 20 changed files with 5,135 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ install:
/usr/bin/Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
fi
- yarn
- cd server && yarn
- cd ..
- cd server && yarn && cd ..
- cd vti && yarn && cd ..

script:
- yarn test
Expand Down
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.23.0 | 2019-12-11

- VTI (Vetur Terminal Interface). #1149.
- Upgrade to TypeScript 3.7 with Optional Chaining and Nullish Coalescing. #1510.
- 🙌 Fix syntax highlighting for interpolation in attributes with numbers (such as `x1`). Thanks to contribution from [Niklas Higi](https://github.com/shroudedcode). #1465.
- 🙌 Fix syntax highlighting for backticked vue code block in Markdown file. Thanks to contribution from [Abdelrahman Awad](https://github.com/logaretm). #1024 and #1485.
Expand Down
2 changes: 2 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ steps:
displayName: Install Dependencies
- bash: cd server && yarn install && cd ..
displayName: Install Server Dependencies
- bash: cd vti && yarn install && cd ..
displayName: Install VTI Dependencies
- bash: yarn compile
displayName: Compile

Expand Down
7 changes: 7 additions & 0 deletions build/copy-snippets.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#!/bin/bash

PDIR=server/dist/modes/vue
DIR=server/dist/modes/vue/veturSnippets

# Create parent dir
if [ ! -d "$PDIR" ]; then
mkdir -p "$PDIR"
fi

# Clean up if snippet DIR already exists
if [ -d "$DIR" ]; then
rm -r "$DIR"
fi
Expand Down
11 changes: 10 additions & 1 deletion client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ export function initializeLanguageClient(vlsModulePath: string, globalSnippetDir
const clientOptions: LanguageClientOptions = {
documentSelector,
synchronize: {
configurationSection: ['vetur', 'emmet', 'html', 'javascript', 'typescript', 'prettier', 'stylusSupremacy'],
configurationSection: [
'vetur',
'emmet',
'html',
'css',
'javascript',
'typescript',
'prettier',
'stylusSupremacy'
],
fileEvents: vscode.workspace.createFileSystemWatcher('{**/*.js,**/*.ts}', false, false, true)
},
initializationOptions: {
Expand Down
4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "vue-language-server",
"description": "vue-language-server",
"version": "0.0.65",
"version": "0.0.67",
"author": "Pine Wu <[email protected]>",
"license": "MIT",
"main": "dist/vueServerMain.js",
"main": "dist/main.js",
"bin": {
"vls": "./bin/vls"
},
Expand Down
110 changes: 109 additions & 1 deletion server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface VLSFormatConfig {
[lang: string]: string;
};
defaultFormatterOptions: {
'prettier': any;
prettier: any;
[lang: string]: any;
};
scriptInitialIndent: boolean;
Expand All @@ -13,3 +13,111 @@ export interface VLSFormatConfig {
useTabs: boolean;
};
}

export interface VLSConfig {
vetur: {
useWorkspaceDependencies: boolean;
completion: {
autoImport: boolean;
useScaffoldSnippets: boolean;
tagCasing: 'initial' | 'kebab';
scaffoldSnippetSources: {
workspace: string;
user: string;
vetur: string;
};
};
grammar: {
customBlocks: { [lang: string]: string };
};
validation: {
template: boolean;
style: boolean;
script: boolean;
};
format: {
enable: boolean;
options: {
tabSize: number;
useTabs: boolean;
};
defaultFormatter: {
[lang: string]: string;
};
defaultFormatterOptions: {
[lang: string]: {};
};
scriptInitialIndent: boolean;
styleInitialIndent: boolean;
};
trace: {
server: 'off' | 'messages' | 'verbose';
};
dev: {
vlsPath: string;
vlsPort: number;
logLevel: 'INFO' | 'DEBUG';
};
experimental: {
templateInterpolationService: boolean;
};
};
}

export interface VLSFullConfig extends VLSConfig {
emmet?: any;
html?: any;
css?: any;
javascript?: any;
typescript?: any;
prettier?: any;
stylusSupremacy?: any;
}

export function getDefaultVLSConfig(): VLSConfig {
return {
vetur: {
useWorkspaceDependencies: false,
validation: {
template: true,
style: true,
script: true
},
completion: {
autoImport: false,
useScaffoldSnippets: false,
tagCasing: 'initial',
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
}
}
};
}
3 changes: 2 additions & 1 deletion server/src/embeddedSupport/languageModes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { VueInfoService } from '../services/vueInfoService';
import { DependencyService, State } from '../services/dependencyService';
import { nullMode } from '../modes/nullMode';
import { getServiceHost, IServiceHost } from '../services/typescriptService/serviceHost';
import { VLSFullConfig } from '../config';

export interface VLSServices {
infoService?: VueInfoService;
Expand All @@ -41,7 +42,7 @@ export interface VLSServices {

export interface LanguageMode {
getId(): string;
configure?(options: any): void;
configure?(options: VLSFullConfig): void;
updateFileInfo?(doc: TextDocument): void;

doValidation?(document: TextDocument): Diagnostic[];
Expand Down
3 changes: 3 additions & 0 deletions server/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { VLS } from './services/vls';

export { VLS };
2 changes: 1 addition & 1 deletion server/src/modes/script/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export async function getJavascriptMode(
getId() {
return 'javascript';
},
configure(c: any) {
configure(c) {
config = c;
},
updateFileInfo(doc: TextDocument): void {
Expand Down
5 changes: 2 additions & 3 deletions server/src/modes/template/htmlMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { findDefinition } from './services/htmlDefinition';
import { getTagProviderSettings, IHTMLTagProvider, CompletionConfiguration } from './tagProviders';
import { getEnabledTagProviders } from './tagProviders';
import { DocumentContext } from '../../types';
import { VLSFormatConfig } from '../../config';
import { VLSFormatConfig, VLSConfig, VLSFullConfig } from '../../config';
import { VueInfoService } from '../../services/vueInfoService';
import { getComponentInfoTagProvider } from './tagProviders/componentInfoTagProvider';

Expand Down Expand Up @@ -48,8 +48,7 @@ export class HTMLMode implements LanguageMode {
return 'html';
}

configure(c: any) {
this.tagProviderSettings = _.assign(this.tagProviderSettings, c.html.suggest);
configure(c: VLSFullConfig) {
this.enabledTagProviders = getEnabledTagProviders(this.tagProviderSettings);
this.config = c;
}
Expand Down
38 changes: 24 additions & 14 deletions server/src/services/vls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
TextDocumentSyncKind,
DocumentFormattingRequest,
Disposable,
DocumentSymbolParams,
CodeActionParams
} from 'vscode-languageserver';
import {
Expand All @@ -24,7 +25,6 @@ import {
Diagnostic,
DocumentHighlight,
DocumentLink,
DocumentSymbolParams,
Hover,
Location,
SignatureHelp,
Expand All @@ -46,6 +46,7 @@ import { DocumentContext, RefactorAction } from '../types';
import { DocumentService } from './documentService';
import { VueHTMLMode } from '../modes/template';
import { logger } from '../log';
import { getDefaultVLSConfig, VLSFullConfig } from '../config';

export class VLS {
// @Todo: Remove this and DocumentContext
Expand Down Expand Up @@ -80,7 +81,11 @@ export class VLS {
}

async init(params: InitializeParams) {
logger.setLevel(_.get(params.initializationOptions.config, ['vetur', 'dev', 'logLevel'], 'INFO'));
const config: VLSFullConfig = params.initializationOptions.config
? _.merge(getDefaultVLSConfig(), params.initializationOptions.config)
: getDefaultVLSConfig();

logger.setLevel(config.vetur.dev.logLevel);

const workspacePath = params.rootPath;
if (!workspacePath) {
Expand All @@ -93,18 +98,17 @@ export class VLS {
this.workspacePath = workspacePath;

await this.vueInfoService.init(this.languageModes);
await this.dependencyService.init(
await this.dependencyService.init(workspacePath, config.vetur.useWorkspaceDependencies);

await this.languageModes.init(
workspacePath,
params.initializationOptions
? _.get(params.initializationOptions.config, ['vetur', 'useWorkspaceDependencies'], false)
: false
{
infoService: this.vueInfoService,
dependencyService: this.dependencyService
},
params.initializationOptions['globalSnippetDir']
);

await this.languageModes.init(workspacePath, {
infoService: this.vueInfoService,
dependencyService: this.dependencyService
}, params.initializationOptions['globalSnippetDir']);

this.setupConfigListeners();
this.setupLSPHandlers();
this.setupCustomLSPHandlers();
Expand All @@ -114,9 +118,7 @@ export class VLS {
this.dispose();
});

if (params.initializationOptions && params.initializationOptions.config) {
this.configure(params.initializationOptions.config);
}
this.configure(config);
}

listen() {
Expand Down Expand Up @@ -158,6 +160,14 @@ export class VLS {
this.lspConnection.onRequest('$/queryVirtualFileInfo', ({ fileName, currFileText }) => {
return (this.languageModes.getMode('vue-html') as VueHTMLMode).queryVirtualFileInfo(fileName, currFileText);
});

this.lspConnection.onRequest('$/getDiagnostics', params => {
const doc = this.documentService.getDocument(params.uri);
if (doc) {
return this.doValidate(doc);
}
return [];
});
}

private async setupDynamicFormatters(settings: any) {
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{ "path": "scripts" },
{ "path": "client" },
{ "path": "server" },
{ "path": "vti" },
{ "path": "test" }
]
}
16 changes: 16 additions & 0 deletions vti/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Vetur Terminal Interface

🚧 Work in progress 🚧

## Usage

```bash
npm i -g vti
# In your Vue project root
vti diagnostics
```

## Todo

- [ ] Exit with 1 when errors are present
- [ ] Formatting
2 changes: 2 additions & 0 deletions vti/bin/vti
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('../dist/cli.js')
26 changes: 26 additions & 0 deletions vti/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "vti",
"description": "Vetur Terminal Interface",
"version": "0.0.1-alpha.1",
"main": "./dist/cli.js",
"bin": "./bin/vti",
"author": "Pine Wu <[email protected]>",
"license": "MIT",
"dependencies": {
"chalk": "^3.0.0",
"glob": "^7.1.2",
"vscode-languageserver": "^5.3.0-next.4",
"vscode-languageserver-protocol": "^3.15.0-next.1",
"vscode-languageserver-types": "^3.15.0-next.1",
"vscode-uri": "^1.0.1",
"vue-language-server": "^0.0.67"
},
"scripts": {
"compile": "tsc -p .",
"watch": "tsc --watch"
},
"devDependencies": {
"@types/glob": "^7.1.0",
"typescript": "^3.7.3"
}
}
Loading

0 comments on commit d56ef88

Please sign in to comment.