-
-
Notifications
You must be signed in to change notification settings - Fork 945
Support for JSON Language Server #1243
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| ;;; lsp-pwsh.el --- vscode-json-languageserver integration -*- lexical-binding: t; -*- | ||
|
|
||
| ;; Copyright (C) 2019 Kien Nguyen | ||
|
|
||
| ;; Author: kien.n.quang at gmail.com | ||
| ;; Keywords: lsp | ||
|
|
||
| ;; This program is free software; you can redistribute it and/or modify | ||
| ;; it under the terms of the GNU General Public License as published by | ||
| ;; the Free Software Foundation, either version 3 of the License, or | ||
| ;; (at your option) any later version. | ||
|
|
||
| ;; This program is distributed in the hope that it will be useful, | ||
| ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| ;; GNU General Public License for more details. | ||
|
|
||
| ;; You should have received a copy of the GNU General Public License | ||
| ;; along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| ;;; Commentary: | ||
|
|
||
| ;; | ||
|
|
||
| ;;; Code: | ||
|
|
||
| (require 'lsp-mode) | ||
| (require 'ht) | ||
| (require 'url-util) | ||
|
|
||
| (defgroup lsp-json nil | ||
| "LSP support for JSON, using vscode-json-languageserver." | ||
| :group 'lsp-mode | ||
| :link '(url-link "https://github.com/vscode-langservers/vscode-json-languageserver") | ||
| :package-version '(lsp-mode . "6.3")) | ||
|
|
||
| (defcustom lsp-json-schemas nil | ||
| "Associate schemas to JSON files in the current project" | ||
| :type '(repeat alist) | ||
| :group 'lsp-json | ||
| :package-version '(lsp-mode . "6.3")) | ||
|
|
||
| (defcustom lsp-json-format-enable t | ||
| "Enable/disable default JSON formatter" | ||
| :type 'boolean | ||
| :group 'lsp-json | ||
| :package-version '(lsp-mode . "6.3")) | ||
|
|
||
| (defcustom lsp-http-proxy nil | ||
| "The URL of the proxy server to use when fetching schema." | ||
| :type 'string | ||
| :group 'lsp-json | ||
| :package-version '(lsp-mode . "6.3")) | ||
|
|
||
| (defcustom lsp-http-proxyStrictSSL t | ||
| "The URL of the proxy server to use when fetching schema." | ||
| :type 'boolean | ||
| :group 'lsp-json | ||
| :package-version '(lsp-mode . "6.3")) | ||
|
|
||
| (lsp-register-custom-settings | ||
| '(("json.format.enable" lsp-json-format-enable t) | ||
| ("json.schemas" lsp-json-schemas) | ||
| ("http.proxy" lsp-http-proxy) | ||
| ("http.proxyStrictSSL" lsp-http-proxyStrictSSL))) | ||
|
|
||
| (defcustom lsp-json-server "vscode-json-languageserver" | ||
| "Json language server executable." | ||
| :type 'string | ||
| :group 'lsp-json | ||
| :package-version '(lsp-mode . "6.3")) | ||
|
|
||
| (defun lsp-json--command () | ||
| "Return the command to start server." | ||
| ;; Install language server | ||
| (unless (and lsp-json-server (executable-find lsp-json-server)) | ||
| (unless (executable-find "npm") | ||
| (user-error "`npm' is not available in your PATH, please install it")) | ||
| (shell-command "npm install -g vscode-json-languageserver")) | ||
| `(,lsp-json-server "--stdio")) | ||
|
|
||
| (defvar lsp-json--extra-init-params | ||
| `(:handledSchemaProtocols ("file" "http" "https"))) | ||
|
|
||
| (defvar lsp-json--major-modes '(json-mode jsonc-mode)) | ||
|
|
||
| (defvar lsp-json--schema-associations | ||
| `(("/*.css-data.json" . ["https://raw.githubusercontent.com/Microsoft/vscode-css-languageservice/master/docs/customData.schema.json"]) | ||
| ("/package.json" . ["https://schemastore.azurewebsites.net/schemas/json/package.json"]) | ||
| ("/*.html-data.json" . ["https://raw.githubusercontent.com/Microsoft/vscode-html-languageservice/master/docs/customData.schema.json"]) | ||
| ("/*.schema.json" . ["http://json-schema.org/draft-07/schema#"]) | ||
| ("/bower.json" . ["https://schemastore.azurewebsites.net/schemas/json/bower.json"]) | ||
| ("/composer.json" . ["https://getcomposer.org/schema.json"]) | ||
| ("/tsconfig.json" . ["https://schemastore.azurewebsites.net/schemas/json/tsconfig.json"]) | ||
| ("/tsconfig.*.json" . ["https://schemastore.azurewebsites.net/schemas/json/tsconfig.json"]) | ||
| ("/typings.json" . ["https://schemastore.azurewebsites.net/schemas/json/typings.json"]) | ||
| ("/.bowerrc" . ["https://schemastore.azurewebsites.net/schemas/json/bowerrc.json"]) | ||
| ("/.babelrc" . ["https://schemastore.azurewebsites.net/schemas/json/babelrc.json"]) | ||
| ("/.babelrc.json" . ["https://schemastore.azurewebsites.net/schemas/json/babelrc.json"]) | ||
| ("/babel.config.json" . ["https://schemastore.azurewebsites.net/schemas/json/babelrc.json"]) | ||
| ("/jsconfig.json" . ["https://schemastore.azurewebsites.net/schemas/json/jsconfig.json"]) | ||
| ("/jsconfig.*.json" . ["https://schemastore.azurewebsites.net/schemas/json/jsconfig.json"]) | ||
| ("/project.json" . ["http://json.schemastore.org/project"]) | ||
| ("/omnisharp.json" . ["http://json.schemastore.org/omnisharp"])) | ||
| "Default json schemas.") | ||
|
|
||
| (defun lsp-json--get-content (_workspace uri) | ||
| "Get content from URI." | ||
| (with-temp-buffer | ||
| (url-insert-file-contents (url-unhex-string uri)) | ||
| (buffer-string))) | ||
|
|
||
| (lsp-register-client | ||
| (make-lsp-client | ||
| :new-connection (lsp-stdio-connection #'lsp-json--command) | ||
| :major-modes lsp-json--major-modes | ||
| :server-id 'json-ls | ||
| :priority -1 | ||
| :completion-in-comments? t | ||
| :initialization-options lsp-json--extra-init-params | ||
| :request-handlers (ht ("vscode/content" #'lsp-json--get-content)) | ||
| :initialized-fn (lambda (w) | ||
| (with-lsp-workspace w | ||
| (lsp--set-configuration (lsp-configuration-section "json")) | ||
| (lsp-notify "json/schemaAssociations" lsp-json--schema-associations))))) | ||
|
|
||
| ;; Compatibility | ||
| (with-eval-after-load 'company-lsp | ||
| (advice-add 'company-tng--supress-post-completion | ||
| :after-while | ||
| (lambda (&rest _) | ||
| (not (memq major-mode lsp-json--major-modes))) | ||
| '((name . --force-post-completion-for-json)))) | ||
|
|
||
| (provide 'lsp-json) | ||
| ;;; lsp-json.el ends here | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this filename in this comment is wrong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, the downfall of copy/paste :(. Will update it next time I touch this file again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries.