Skip to content

Commit

Permalink
Merge pull request #2 from adamvoss/npmPublishing
Browse files Browse the repository at this point in the history
Configure for publication on NPM
  • Loading branch information
adamvoss committed Aug 28, 2017
2 parents 90a132d + 4cd3c14 commit e39e02d
Show file tree
Hide file tree
Showing 31 changed files with 562 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lib/
/lib/
node_modules/
package-lock.json
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

23 changes: 18 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
language: node_js
dist: trusty
sudo: false

node_js:
- "6"

before_install:
- ./npminstall.sh
- '6'
- '7'
- '8'
deploy:
- provider: npm
skip_cleanup: true
email: [email protected]
api_key:
secure: >-
sNO19+NGAmQncPhRP9LA59Q7TnvBmJ+aHxaNXaLFUnwVy1O4HWOeH4B0cqaaNOOpuknAEhtuU1p5E9XpehHHgW18XdTdiHuE81uOFQP1CDgEC8EKidOM85CsTlEyN8J9bF+dVwoCnyttPjk0Gg3Ohm9A6apBvn6TDJSAehM7Z03M2Py65o4svvViBA8q2tV5P1Jyl6NT7E/1YRWpYV+GnB2zpWsodk3Vu/ZoMFFjKVjxsl+Z5OxfkVb/+AW6fxSHRJjN7/qFy8ycQfz2gU/iMNxF6nD5tsQWHQf8uRTrRWkDrDpFiU6LC67QwA2eVRoS/DZYTSvUi+0Y45ZD8lomNsXq3FekpbcKv8OGcv+G2UKGO3C57wd9keqqFyEFYHfBAoiO292yjGkWqo0I4E8cFYnKE8Wz/NLGW4uRAcOMyi6vfCWhNaQgUsS4xMNjgsrlapXjtw94ql+fIqQX8MKmT2R3gpt0BbMK2y4czE0gjAtMUbkZc7JEpzCR7JPkXHrKCCM56QJgHpaEbgFQTTZOkyEfxAFUyM6JxJ/wyN1u3s+TDhEQH4aIykCTcd3LeJcBQF5AMRUqRBxa+tpV+P9YYww4UayTQdSJjWzmO9DRaNTeanv0B0xJUOKjNk6V7xKUPixKcwlSDGr2Ve7UW2CQhw+gqKrWTT2s+DaxfWm4+BY=
on:
tags: true
- provider: releases
api_key:
secure: >-
hjSix3LS2pLuV1OOlgEQZt1GDKPLh/8gu81RkPXKfzTR6mWmBdSfPM0UMO+eUPYSTMFuUj1xNAFKwBu1HOKE6bfYtpMoYHGH+t7MDOUB8hgbdgVeBC+rxXYM8fyrGCkxIGyZVZpmMCKHrmH2t/PelMMZdD/2shcCPFPUvlPN3t61nS+UB8PCHQVUCkw+29ET7pB0iJW948aPbgFcf1glaXSLvj0fqbvrHmgW9x/1HqVO/TbdrK2WGa9nw8LCq5OOR3kkWn2HvdiamNV1EOBHQ94YfE399xLhg7m3V7JIQsLpXNPQJy/mKb1saFzIVh2dsY+5Iq+SW3iM/R47VYE4VOaFHdccEK4KrUCSKgLkaucfZd08s1/YeFp3774xTTpFhcZZyhhi+//MT3qfGS20ZGPiVDKRZKi2YTw72grhJ8dOuHlz3clUeNJvfkwCImlfYxFuINiBMFCJ9D8w+5cu+SW/bJLC7WKy73YAl0np4sLKuqGl0OvxXX0lBUHKKl9XLk81isIMJyYkL+XU6A4fcer1zgnSV50zG5rtqLLd8BJ4rR7+gQKLXDWs7+PexvOpS54Y3ZCv0O5EAjNzDdQ3whJslgcyi/AVfHGSWWf6AthTcO5hddd8Rc8jnyO834gJhEBNtCZZrgqSZWGY2POMEKabXrt5lVFKD7u721kZSsE=
on:
tags: true
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# vscode-yaml-languageservice
YAML language service built on top of [vscode-json-languageservice](https://github.com/Microsoft/vscode-json-languageservice/) and intended for similar usage. It powers the [YAML language extension for Visual Studio Code](https://github.com/adamvoss/vscode-yaml).

[![NPM version](https://img.shields.io/npm/v/vscode-yaml-languageservice.svg)](http://www.npmjs.com/package/vscode-yaml-languageservice)

## Why
To provide a YAML editor experience that has parity with the JSON.

Expand All @@ -14,14 +16,20 @@ The following functionality is incomplete:
- *doResolve* resolves a completion proposals.

## Contributing
Contributions are welcome! To install dependencies and begin work, run:
Contributions are welcome!

To install dependencies and begin work, run:

```sh
git submodule update --init
./npminstall.sh
npm install
```

To run tests:

```
npm test
```

This depends on internals of [vscode-json-languageservice](https://github.com/Microsoft/vscode-json-languageservice/) so importing its NPM module was not an option. Therefore, you must use the above commands instead of `npm install`.
### vscode-json-languageservice type definitions

## Installation
If this is useful to you, and you would like to see it on NPM, please submit a pull request or open an issue.
This depends on internals of [vscode-json-languageservice](https://github.com/Microsoft/vscode-json-languageservice/) where relevant type information is not currently published (see [Microsoft/vscode-json-languageservice#11](https://github.com/Microsoft/vscode-json-languageservice/pull/11)). To workaround this limitation, external type definitions are used. When newer type definitions are needed, manually compile **vscode-json-languageservice** locally and copy the resulting type definitions over the definitions in the `types` directory of this project.
5 changes: 0 additions & 5 deletions npminstall.sh

This file was deleted.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "vscode-yaml-languageservice",
"version": "0.0.1",
"version": "0.1.0",
"description": "Language service for YAML",
"main": "./lib/src/yamlLanguageService.js",
"typings": "./lib/src/jsonLanguageService",
"main": "./lib/yamlLanguageService.js",
"typings": "./lib/yamlLanguageService",
"author": "Adam Voss",
"license": "MIT",
"repository": {
Expand All @@ -19,15 +19,15 @@
"dependencies": {
"js-yaml": "^3.8.4",
"jsonc-parser": "^1.0.0",
"vscode-json-languageservice": "file:./vscode-json-languageservice",
"vscode-json-languageservice": "^2.0.14",
"vscode-nls": "^2.0.2",
"yaml-ast-parser": "0.0.34"
},
"devDependencies": {
"@types/js-yaml": "^3.5.31",
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.31",
"@types/node": "^8.0.25",
"mocha": "^3.4.2",
"typescript": "2.3.4"
"typescript": "^2.4.2"
}
}
4 changes: 2 additions & 2 deletions src/parser/yamlParser.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import { JSONDocument, ASTNode, ErrorCode, BooleanASTNode, NullASTNode, ArrayASTNode, NumberASTNode, ObjectASTNode, PropertyASTNode, StringASTNode, IError, IApplicableSchema } from '../../vscode-json-languageservice/src/parser/jsonParser';
import { JSONSchema } from '../../vscode-json-languageservice/src/jsonSchema';
import { JSONDocument, ASTNode, ErrorCode, BooleanASTNode, NullASTNode, ArrayASTNode, NumberASTNode, ObjectASTNode, PropertyASTNode, StringASTNode, IError, IApplicableSchema } from 'vscode-json-languageservice/lib/parser/jsonParser';
import { JSONSchema } from 'vscode-json-languageservice/lib/jsonSchema';

import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();
Expand Down
4 changes: 2 additions & 2 deletions src/services/yamlFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import jsyaml = require('js-yaml')
import {EOL} from 'os'
import { EOL } from 'os';
import { TextDocument, Range, Position, FormattingOptions, TextEdit } from 'vscode-languageserver-types';

export function format(document: TextDocument, options: FormattingOptions): TextEdit[] {
Expand All @@ -15,7 +15,7 @@ export function format(document: TextDocument, options: FormattingOptions): Text
const yaml = documents[0]
newText = jsyaml.safeDump(yaml, { indent: options.tabSize })
}
else{
else {
const formatted = documents.map(d => jsyaml.safeDump(d, { indent: options.tabSize }))
newText = '%YAML 1.2' + EOL + '---' + EOL + formatted.join('...' + EOL + '---' + EOL) + '...' + EOL
}
Expand Down
2 changes: 2 additions & 0 deletions src/test/completion.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict"

import "mocha";

import assert = require('assert');

import { TextDocument } from "vscode-languageserver-types";
Expand Down
2 changes: 2 additions & 0 deletions src/test/documentPositionCalculator.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "mocha";

import assert = require('assert');

import * as calc from '../documentPositionCalculator'
Expand Down
1 change: 1 addition & 0 deletions src/test/nodeOffset.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

import "mocha";
import assert = require('assert');
import YamlParser = require('../parser/yamlParser');

Expand Down
9 changes: 5 additions & 4 deletions src/test/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import "mocha";
import assert = require('assert');
import YamlParser = require('../parser/yamlParser');
import Parser = require('../../vscode-json-languageservice/src/parser/jsonParser');
import SchemaService = require('../../vscode-json-languageservice/src/services/jsonSchemaService');
import JsonSchema = require('../../vscode-json-languageservice/src/jsonSchema');
import Parser = require('vscode-json-languageservice/lib/parser/jsonParser');
import SchemaService = require('vscode-json-languageservice/lib/services/jsonSchemaService');
import JsonSchema = require('vscode-json-languageservice/lib/jsonSchema');

suite('YAML Parser', () => {

Expand Down Expand Up @@ -1168,7 +1169,7 @@ suite('YAML Parser', () => {
},
dependencies: {
a: ['b']
}
} as JsonSchema.JSONSchemaMap
};

doc.validate(schema);
Expand Down
1 change: 1 addition & 0 deletions src/test/yamlFormatter.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "mocha";
import { format } from '../services/yamlFormatter'
import { TextDocument } from 'vscode-languageserver-types';
import assert = require("assert");
Expand Down
7 changes: 6 additions & 1 deletion src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"outDir": "../lib",
"lib": [
"es6"
]
],
"baseUrl": "../types",
"typeRoots": [
"../node_modules/@types",
"../types"
]
}
}
18 changes: 9 additions & 9 deletions src/yamlLanguageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
import {TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic,
TextEdit, FormattingOptions, MarkedString} from 'vscode-languageserver-types';

import {JSONCompletion} from '../vscode-json-languageservice/src/services/jsonCompletion';
import {JSONHover} from '../vscode-json-languageservice/src/services/jsonHover';
import {JSONValidation} from '../vscode-json-languageservice/src/services/jsonValidation';
import {JSONSchema} from '../vscode-json-languageservice/src/jsonSchema';
import {JSONDocumentSymbols} from '../vscode-json-languageservice/src/services/jsonDocumentSymbols';
import {parse as JSONDocumentConfig} from '../vscode-json-languageservice/src/parser/jsonParser';
import {JSONCompletion} from 'vscode-json-languageservice/lib/services/jsonCompletion';
import {JSONHover} from 'vscode-json-languageservice/lib/services/jsonHover';
import {JSONValidation} from 'vscode-json-languageservice/lib/services/jsonValidation';
import {JSONSchema} from 'vscode-json-languageservice/lib/jsonSchema';
import {JSONDocumentSymbols} from 'vscode-json-languageservice/lib/services/jsonDocumentSymbols';
import {parse as JSONDocumentConfig} from 'vscode-json-languageservice/lib/parser/jsonParser';

import {parse as parseYAML} from './parser/yamlParser';
import {isInComment} from './services/yamlCompletion'
import {format as formatYAML} from './services/yamlFormatter';

import {schemaContributions} from '../vscode-json-languageservice/src/services/configuration';
import {JSONSchemaService} from '../vscode-json-languageservice/src/services/jsonSchemaService';
import {JSONWorkerContribution, JSONPath, Segment, CompletionsCollector} from '../vscode-json-languageservice/src/jsonContributions';
import {schemaContributions} from 'vscode-json-languageservice/lib/services/configuration';
import {JSONSchemaService} from 'vscode-json-languageservice/lib/services/jsonSchemaService';
import {JSONWorkerContribution, JSONPath, Segment, CompletionsCollector} from 'vscode-json-languageservice/lib/jsonContributions';

export type JSONDocument = {}
export type YAMLDocument = { documents: JSONDocument[]}
Expand Down
2 changes: 1 addition & 1 deletion test/mocha.opts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
--ui tdd
--useColors true
./lib/src/test
./lib/test
17 changes: 17 additions & 0 deletions types/vscode-json-languageservice/lib/jsonContributions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Thenable, MarkedString, CompletionItem } from './jsonLanguageService';
export interface JSONWorkerContribution {
getInfoContribution(uri: string, location: JSONPath): Thenable<MarkedString[]>;
collectPropertyCompletions(uri: string, location: JSONPath, currentWord: string, addValue: boolean, isLast: boolean, result: CompletionsCollector): Thenable<any>;
collectValueCompletions(uri: string, location: JSONPath, propertyKey: string, result: CompletionsCollector): Thenable<any>;
collectDefaultCompletions(uri: string, result: CompletionsCollector): Thenable<any>;
resolveCompletion?(item: CompletionItem): Thenable<CompletionItem>;
}
export declare type Segment = string | number;
export declare type JSONPath = Segment[];
export interface CompletionsCollector {
add(suggestion: CompletionItem): void;
error(message: string): void;
log(message: string): void;
setAsIncomplete(): void;
getNumberOfProposals(): number;
}
115 changes: 115 additions & 0 deletions types/vscode-json-languageservice/lib/jsonLanguageService.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, FormattingOptions, MarkedString } from 'vscode-languageserver-types';
import { JSONSchema } from './jsonSchema';
import { JSONWorkerContribution, JSONPath, Segment, CompletionsCollector } from './jsonContributions';
export declare type JSONDocument = {};
export { JSONSchema, JSONWorkerContribution, JSONPath, Segment, CompletionsCollector };
export { TextDocument, Position, CompletionItem, CompletionList, Hover, Range, SymbolInformation, Diagnostic, TextEdit, FormattingOptions, MarkedString };
export interface LanguageService {
configure(settings: LanguageSettings): void;
doValidation(document: TextDocument, jsonDocument: JSONDocument): Thenable<Diagnostic[]>;
parseJSONDocument(document: TextDocument): JSONDocument;
resetSchema(uri: string): boolean;
doResolve(item: CompletionItem): Thenable<CompletionItem>;
doComplete(document: TextDocument, position: Position, doc: JSONDocument): Thenable<CompletionList>;
findDocumentSymbols(document: TextDocument, doc: JSONDocument): SymbolInformation[];
findColorSymbols(document: TextDocument, doc: JSONDocument): Thenable<Range[]>;
doHover(document: TextDocument, position: Position, doc: JSONDocument): Thenable<Hover>;
format(document: TextDocument, range: Range, options: FormattingOptions): TextEdit[];
}
export interface LanguageSettings {
/**
* If set, the validator will return syntax errors.
*/
validate?: boolean;
/**
* If set, comments are toleranted. If not set, a syntax error is emmited for comments.
*/
allowComments?: boolean;
/**
* A list of known schemas and/or associations of schemas to file names.
*/
schemas?: SchemaConfiguration[];
}
export interface SchemaConfiguration {
/**
* The URI of the schema, which is also the identifier of the schema.
*/
uri: string;
/**
* A list of file names that are associated to the schema. The '*' wildcard can be used. For example '*.schema.json', 'package.json'
*/
fileMatch?: string[];
/**
* The schema for the given URI.
* If no schema is provided, the schema will be fetched with the schema request service (if available).
*/
schema?: JSONSchema;
}
export interface WorkspaceContextService {
resolveRelativePath(relativePath: string, resource: string): string;
}
/**
* The schema request service is used to fetch schemas. The result should the schema file comment, or,
* in case of an error, a displayable error string
*/
export interface SchemaRequestService {
(uri: string): Thenable<string>;
}
export interface PromiseConstructor {
/**
* Creates a new Promise.
* @param executor A callback used to initialize the promise. This callback is passed two arguments:
* a resolve callback used resolve the promise with a value or the result of another promise,
* and a reject callback used to reject the promise with a provided reason or error.
*/
new <T>(executor: (resolve: (value?: T | Thenable<T>) => void, reject: (reason?: any) => void) => void): Thenable<T>;
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T>(values: Array<T | Thenable<T>>): Thenable<T[]>;
/**
* Creates a new rejected promise for the provided reason.
* @param reason The reason the promise was rejected.
* @returns A new rejected Promise.
*/
reject<T>(reason: any): Thenable<T>;
/**
* Creates a new resolved promise for the provided value.
* @param value A promise.
* @returns A promise whose internal state matches the provided promise.
*/
resolve<T>(value: T | Thenable<T>): Thenable<T>;
}
export interface Thenable<R> {
/**
* Attaches callbacks for the resolution and/or rejection of the Promise.
* @param onfulfilled The callback to execute when the Promise is resolved.
* @param onrejected The callback to execute when the Promise is rejected.
* @returns A Promise for the completion of which ever callback is executed.
*/
then<TResult>(onfulfilled?: (value: R) => TResult | Thenable<TResult>, onrejected?: (reason: any) => TResult | Thenable<TResult>): Thenable<TResult>;
then<TResult>(onfulfilled?: (value: R) => TResult | Thenable<TResult>, onrejected?: (reason: any) => void): Thenable<TResult>;
}
export interface LanguageServiceParams {
/**
* The schema request service is used to fetch schemas. The result should the schema file comment, or,
* in case of an error, a displayable error string
*/
schemaRequestService?: SchemaRequestService;
/**
* The workspace context is used to resolve relative paths for relative schema references.
*/
workspaceContext?: WorkspaceContextService;
/**
* An optional set of completion and hover participants.
*/
contributions?: JSONWorkerContribution[];
/**
* A promise constructor. If not set, the ES5 Promise will be used.
*/
promiseConstructor?: PromiseConstructor;
}
export declare function getLanguageService(params: LanguageServiceParams): LanguageService;
Loading

0 comments on commit e39e02d

Please sign in to comment.