prettier-language-server 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -8
- package/bin/prettier-language-server +2 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -1,28 +1,39 @@
|
|
|
1
1
|
# prettier-language-server
|
|
2
2
|
|
|
3
|
+
**A lightweight and fast Language Server for Prettier**
|
|
4
|
+
|
|
5
|
+
The `prettier-language-server` is designed to be simple, fast, and focused, offering only essential features for formatting code with Prettier.
|
|
6
|
+
|
|
3
7
|
## Features
|
|
4
8
|
|
|
5
|
-
|
|
6
|
-
and the set of the features is quite limited.
|
|
9
|
+
This language server provides a minimal set of features to ensure fast performance:
|
|
7
10
|
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
+
- **Range Formatting**: Supports out-of-the-box range-based formatting.
|
|
12
|
+
- **No Diagnostics**: Focuses solely on formatting without providing diagnostics.
|
|
13
|
+
- **Prettier Config Resolution**: Automatically resolves and caches the Prettier configuration based on the workspace folder.
|
|
11
14
|
|
|
12
15
|
## Requirements
|
|
13
16
|
|
|
14
|
-
-
|
|
17
|
+
- **Node.js** version >= 13.2 is required.
|
|
15
18
|
|
|
16
19
|
## Installation
|
|
17
20
|
|
|
21
|
+
To install globally via npm, run:
|
|
22
|
+
|
|
18
23
|
```sh
|
|
19
24
|
npm i -g prettier-language-server
|
|
20
25
|
```
|
|
21
26
|
|
|
22
|
-
##
|
|
27
|
+
## Configuration for Neovim
|
|
28
|
+
|
|
29
|
+
If you're using [nvim-lspconfig](https://github.com/neovim/nvim-lspconfig), you can configure the `prettier-language-server` as follows:
|
|
30
|
+
|
|
31
|
+
### Define the Language Server Configuration
|
|
32
|
+
|
|
33
|
+
Create a new configuration file at `lua/lspconfig/configs/prettier_ls.lua` with the following content:
|
|
23
34
|
|
|
24
35
|
<details>
|
|
25
|
-
<summary>lua/lspconfig/configs/
|
|
36
|
+
<summary>lua/lspconfig/configs/prettier_ls.lua</summary>
|
|
26
37
|
|
|
27
38
|
```lua
|
|
28
39
|
local root_file = {
|
|
@@ -72,3 +83,17 @@ return {
|
|
|
72
83
|
```
|
|
73
84
|
|
|
74
85
|
</details>
|
|
86
|
+
|
|
87
|
+
### Initialize the Language Server
|
|
88
|
+
|
|
89
|
+
Add the following code to initialize the language server:
|
|
90
|
+
|
|
91
|
+
```lua
|
|
92
|
+
require('lspconfig').prettier_ls.setup({})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Credits
|
|
96
|
+
|
|
97
|
+
- https://github.com/prettier/prettier
|
|
98
|
+
- https://github.com/fsouza/prettierd
|
|
99
|
+
- https://github.com/microsoft/vscode-languageserver-node
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var W=Object.create;var{getPrototypeOf:d,defineProperty:Q,getOwnPropertyNames:l}=Object;var w=Object.prototype.hasOwnProperty;var q=(v,b,y)=>{y=v!=null?W(d(v)):{};let j=b||!v||!v.__esModule?Q(y,"default",{value:v,enumerable:!0}):y;for(let u of l(v))if(!w.call(j,u))Q(j,u,{get:()=>v[u],enumerable:!0});return j};var E=(v,b)=>()=>(b||v((b={exports:{}}).exports,b),b.exports);var I=(v,b)=>{for(var y in b)Q(v,y,{get:b[y],enumerable:!0,configurable:!0,set:(j)=>b[y]=()=>j})};var U=(v,b)=>()=>(v&&(b=v(v=0)),b);var Y="0.0.3";var X=()=>{};var Z={};I(Z,{createConnection:()=>C});async function C(){let v=await import("node:path"),b=await import("prettier"),{URI:y}=await import("vscode-uri"),{TextDocument:j}=await import("vscode-languageserver-textdocument"),u=await import("vscode-languageserver/node.js"),K=new u.TextDocuments(j),B=u.createConnection(process.stdin,process.stdout);K.listen(B);let L,M,N;async function $(i){M??=await b.resolveConfigFile(i),N??=await b.resolveConfig(i,{editorconfig:!0,useCache:!1,...M&&{config:M}})}async function S(i){if(N)return N;return await b.resolveConfig(i,{editorconfig:!0,useCache:!0})}async function V(i,G,s){let A=y.parse(i).fsPath,z=await S(A);return await b.format(G,{...z,...s,filepath:A})}return B.onInitialize(async({workspaceFolders:i})=>{if(L=i?.[0],L)await $(v.join(y.parse(L.uri).fsPath,"_"));return{capabilities:{textDocumentSync:u.TextDocumentSyncKind.Incremental,documentFormattingProvider:!0,documentRangeFormattingProvider:!0}}}),B.onDocumentFormatting(async(i,G)=>{let s=K.get(i.textDocument.uri);if(!s)return null;let A=s.getText(),z={line:0,character:0},H=s.positionAt(A.length),J=u.Range.create(z,H),O=await V(s.uri,A);return[u.TextEdit.replace(J,O)]}),B.onDocumentRangeFormatting(async(i,G)=>{let s=K.get(i.textDocument.uri);if(!s)return null;let A=s.getText(),z=s.offsetAt(i.range.start),H=s.offsetAt(i.range.end),J=await V(s.uri,A,{rangeStart:z,rangeEnd:H}),O=J.slice(z,H+J.length-A.length);return[u.TextEdit.replace(i.range,O)]}),B}var _=E(()=>{X();async function F(){let{parseArgs:v}=await import("node:util"),{createConnection:b}=await Promise.resolve().then(() => Z),{values:y}=v({options:{version:{type:"boolean",short:"v"}},strict:!0,allowPositionals:!0});if(y.version)process.stdout.write(Y),process.exit(0);(await b()).listen()}F()});Promise.resolve().then(() => q(_()));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prettier-language-server",
|
|
3
|
-
"type": "
|
|
4
|
-
"version": "0.0.
|
|
3
|
+
"type": "commonjs",
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=13.2.0"
|
|
7
7
|
},
|
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
-
"files": [
|
|
12
|
+
"files": [
|
|
13
|
+
"bin/prettier-language-server"
|
|
14
|
+
],
|
|
13
15
|
"bin": "./bin/prettier-language-server",
|
|
14
16
|
"scripts": {
|
|
15
17
|
"build:node": "bun ./build/node.ts"
|