Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
use json extension source for base code
Browse files Browse the repository at this point in the history
  • Loading branch information
bungcip committed Nov 12, 2016
1 parent 6512b9d commit 2a2d41e
Show file tree
Hide file tree
Showing 10 changed files with 1,305 additions and 110 deletions.
Empty file added contoh.toml
Empty file.
146 changes: 75 additions & 71 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,73 +1,77 @@
{
"name": "better-toml",
"displayName": "Better TOML",
"description": "Better TOML Language support",
"version": "0.2.0",
"publisher": "bungcip",
"license": "MIT",
"homepage": "https://github.com/bungcip/better-toml/blob/master/README.md",
"repository": {
"type": "git",
"url": "https://github.com/bungcip/better-toml.git"
},
"bugs": {
"url": "https://github.com/bungcip/better-toml/issues",
"email": "[email protected]"
},
"engines": {
"vscode": "^1.5.0"
},
"categories": [
"Languages"
],
"keywords": [
"toml"
],
"activationEvents": [
"onLanguage:toml"
],
"main": "./out/src/extension",
"contributes": {
"languages": [
{
"id": "toml",
"aliases": [
"TOML", "toml"
],
"extensions": [
".toml"
],
"mimetypes": [
"text/x-toml"
],
"configuration": "./language-configuration.json"
}
"name": "better-toml",
"displayName": "Better TOML",
"description": "Better TOML Language support",
"version": "0.2.0",
"publisher": "bungcip",
"license": "MIT",
"homepage": "https://github.com/bungcip/better-toml/blob/master/README.md",
"repository": {
"type": "git",
"url": "https://github.com/bungcip/better-toml.git"
},
"bugs": {
"url": "https://github.com/bungcip/better-toml/issues",
"email": "[email protected]"
},
"engines": {
"vscode": "^1.5.0"
},
"categories": [
"Languages"
],
"keywords": [
"toml"
],
"activationEvents": [
"onLanguage:toml"
],
"main": "./out/src/extension",
"contributes": {
"languages": [
{
"id": "toml",
"aliases": [
"TOML",
"toml"
],

"grammars": [
{
"language": "toml",
"scopeName": "source.toml",
"path": "./syntaxes/TOML.tmLanguage"
}
]

},
"scripts": {
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"dependencies": {
"vscode-languageclient": "^2.6.0",
"vscode-languageserver": "^2.6.0",
"toml": "^2.3.0"
},
"devDependencies": {
"typescript": "^2.0.6",
"vscode": "^1.0.3",
"mocha": "^3.1.2",
"@types/node": "^6.0.46",
"@types/mocha": "^2.2.32"
}
}
"extensions": [
".toml"
],
"mimetypes": [
"text/x-toml"
],
"configuration": "./language-configuration.json"
}
],
"grammars": [
{
"language": "toml",
"scopeName": "source.toml",
"path": "./syntaxes/TOML.tmLanguage"
}
]
},
"scripts": {
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
},
"dependencies": {
"ajv": "^4.8.2",
"request-light": "^0.1.0",
"toml": "^2.3.0",
"vscode-languageclient": "^2.6.0",
"vscode-languageserver": "^2.6.0",
"vscode-json-languageservice": "^1.1.7",
"vscode-nls": "^2.0.1"
},
"devDependencies": {
"typescript": "^2.0.6",
"vscode": "^1.0.3",
"mocha": "^3.1.2",
"@types/node": "^6.0.46",
"@types/mocha": "^2.2.32",
"@types/ajv": "^0.0.3"
}
}
6 changes: 6 additions & 0 deletions server/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"properties": {
"foo": { "type": "string" },
"bar": { "type": "number", "maximum": 3 }
}
}
66 changes: 66 additions & 0 deletions server/jsoncontributions/fileAssociationContribution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import { MarkedString, CompletionItemKind, CompletionItem } from 'vscode-languageserver';
import Strings = require('../utils/strings');
import { JSONWorkerContribution, JSONPath, CompletionsCollector } from 'vscode-json-languageservice';

import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();

let globProperties: CompletionItem[] = [
{ kind: CompletionItemKind.Value, label: localize('assocLabelFile', "Files with Extension"), insertText: '"*.{{extension}}": "{{language}}"', documentation: localize('assocDescriptionFile', "Map all files matching the glob pattern in their filename to the language with the given identifier.") },
{ kind: CompletionItemKind.Value, label: localize('assocLabelPath', "Files with Path"), insertText: '"/{{path to file}}/*.{{extension}}": "{{language}}"', documentation: localize('assocDescriptionPath', "Map all files matching the absolute path glob pattern in their path to the language with the given identifier.") }
];

export class FileAssociationContribution implements JSONWorkerContribution {
private languageIds: string[];

constructor() {
}

public setLanguageIds(ids: string[]): void {
this.languageIds = ids;
}

private isSettingsFile(resource: string): boolean {
return Strings.endsWith(resource, '/settings.json');
}

public collectDefaultCompletions(resource: string, result: CompletionsCollector): Thenable<any> {
return null;
}

public collectPropertyCompletions(resource: string, location: JSONPath, currentWord: string, addValue: boolean, isLast: boolean, result: CompletionsCollector): Thenable<any> {
if (this.isSettingsFile(resource) && location.length === 1 && location[0] === 'files.associations') {
globProperties.forEach(e => {
e.filterText = e.insertText;
result.add(e);
});
}

return null;
}

public collectValueCompletions(resource: string, location: JSONPath, currentKey: string, result: CompletionsCollector): Thenable<any> {
if (this.isSettingsFile(resource) && location.length === 1 && location[0] === 'files.associations') {
this.languageIds.forEach(l => {
result.add({
kind: CompletionItemKind.Value,
label: l,
insertText: JSON.stringify('{{' + l + '}}'),
filterText: JSON.stringify(l)
});
});
}

return null;
}

public getInfoContribution(resource: string, location: JSONPath): Thenable<MarkedString[]> {
return null;
}
}
67 changes: 67 additions & 0 deletions server/jsoncontributions/globPatternContribution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';

import { MarkedString, CompletionItemKind, CompletionItem } from 'vscode-languageserver';
import Strings = require('../utils/strings');
import { JSONWorkerContribution, JSONPath, CompletionsCollector } from 'vscode-json-languageservice';

import * as nls from 'vscode-nls';
const localize = nls.loadMessageBundle();

let globProperties: CompletionItem[] = [
{ kind: CompletionItemKind.Value, label: localize('fileLabel', "Files by Extension"), insertText: '"**/*.{{extension}}": true', documentation: localize('fileDescription', "Match all files of a specific file extension.") },
{ kind: CompletionItemKind.Value, label: localize('filesLabel', "Files with Multiple Extensions"), insertText: '"**/*.{ext1,ext2,ext3}": true', documentation: localize('filesDescription', "Match all files with any of the file extensions.") },
{ kind: CompletionItemKind.Value, label: localize('derivedLabel', "Files with Siblings by Name"), insertText: '"**/*.{{source-extension}}": { "when": "$(basename).{{target-extension}}" }', documentation: localize('derivedDescription', "Match files that have siblings with the same name but a different extension.") },
{ kind: CompletionItemKind.Value, label: localize('topFolderLabel', "Folder by Name (Top Level)"), insertText: '"{{name}}": true', documentation: localize('topFolderDescription', "Match a top level folder with a specific name.") },
{ kind: CompletionItemKind.Value, label: localize('topFoldersLabel', "Folders with Multiple Names (Top Level)"), insertText: '"{folder1,folder2,folder3}": true', documentation: localize('topFoldersDescription', "Match multiple top level folders.") },
{ kind: CompletionItemKind.Value, label: localize('folderLabel', "Folder by Name (Any Location)"), insertText: '"**/{{name}}": true', documentation: localize('folderDescription', "Match a folder with a specific name in any location.") },
];

let globValues: CompletionItem[] = [
{ kind: CompletionItemKind.Value, label: localize('trueLabel', "true"), insertText: 'true', documentation: localize('trueDescription', "Enable the pattern.") },
{ kind: CompletionItemKind.Value, label: localize('falseLabel', "false"), insertText: 'false', documentation: localize('falseDescription', "Disable the pattern.") },
{ kind: CompletionItemKind.Value, label: localize('derivedLabel', "Files with Siblings by Name"), insertText: '{ "when": "$(basename).{{extension}}" }', documentation: localize('siblingsDescription', "Match files that have siblings with the same name but a different extension.") }
];

export class GlobPatternContribution implements JSONWorkerContribution {

constructor() {
}

private isSettingsFile(resource: string): boolean {
return Strings.endsWith(resource, '/settings.json');
}

public collectDefaultCompletions(resource: string, result: CompletionsCollector): Thenable<any> {
return null;
}

public collectPropertyCompletions(resource: string, location: JSONPath, currentWord: string, addValue: boolean, isLast: boolean, result: CompletionsCollector): Thenable<any> {
if (this.isSettingsFile(resource) && location.length === 1 && ((location[0] === 'files.exclude') || (location[0] === 'search.exclude'))) {
globProperties.forEach(e => {
e.filterText = e.insertText;
result.add(e);
});
}

return null;
}

public collectValueCompletions(resource: string, location: JSONPath, currentKey: string, result: CompletionsCollector): Thenable<any> {
if (this.isSettingsFile(resource) && location.length === 1 && ((location[0] === 'files.exclude') || (location[0] === 'search.exclude'))) {
globValues.forEach(e => {
e.filterText = e.insertText;
result.add(e);
});
}

return null;
}

public getInfoContribution(resource: string, location: JSONPath): Thenable<MarkedString[]> {
return null;
}
}
Loading

0 comments on commit 2a2d41e

Please sign in to comment.