prettier-language-server 0.0.2 → 0.0.4

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 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
- The idea of this language server is to be as simple and fast as possible,
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
- - Out of the box Range Formatting
9
- - Doesn't provide diagnostics, only formatting
10
- - Resolves and caches the prettier config based on the workspace folder
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
- - node.js >=13.2
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
- ## Neovim Language Server Configuration
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/prettierls.lua</summary>
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
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- var W=Object.create;var{getPrototypeOf:l,defineProperty:Q,getOwnPropertyNames:w}=Object;var E=Object.prototype.hasOwnProperty;var z=(b,v,i)=>{i=b!=null?W(l(b)):{};let j=v||!b||!b.__esModule?Q(i,"default",{value:b,enumerable:!0}):i;for(let A of w(b))if(!E.call(j,A))Q(j,A,{get:()=>b[A],enumerable:!0});return j};var I=(b,v)=>{for(var i in v)Q(b,i,{get:v[i],enumerable:!0,configurable:!0,set:(j)=>v[i]=()=>j})};var X=(b,v)=>()=>(b&&(v=b(b=0)),v);var Z="0.0.1";var Y=()=>{};var _={};I(_,{createConnection:()=>n});async function n(){let b=await import("node:path"),v=await import("prettier"),{URI:i}=await import("vscode-uri"),{TextDocument:j}=await import("vscode-languageserver-textdocument"),A=await import("vscode-languageserver/node.js"),K=new A.TextDocuments(j),B=A.createConnection(process.stdin,process.stdout);K.listen(B);let L,M,N;async function d(y){M??=await v.resolveConfigFile(y),N??=await v.resolveConfig(y,{editorconfig:!0,useCache:!1,...M&&{config:M}})}async function S(y){if(N)return N;return await v.resolveConfig(y,{editorconfig:!0,useCache:!0})}async function V(y,G,u){let q=i.parse(y).fsPath,s=await S(q);return await v.format(G,{...s,...u,filepath:q})}return B.onInitialize(async({workspaceFolders:y})=>{if(L=y?.[0],L)await d(b.join(i.parse(L.uri).fsPath,"_"));return{capabilities:{textDocumentSync:A.TextDocumentSyncKind.Incremental,documentFormattingProvider:!0,documentRangeFormattingProvider:!0}}}),B.onDocumentFormatting(async(y,G)=>{let u=K.get(y.textDocument.uri);if(!u)return null;let q=u.getText(),s={line:0,character:0},H=u.positionAt(q.length),J=A.Range.create(s,H),O=await V(u.uri,q);return[A.TextEdit.replace(J,O)]}),B.onDocumentRangeFormatting(async(y,G)=>{let u=K.get(y.textDocument.uri);if(!u)return null;let q=u.getText(),s=u.offsetAt(y.range.start),H=u.offsetAt(y.range.end),J=await V(u.uri,q,{rangeStart:s,rangeEnd:H}),O=J.slice(s,H+J.length-q.length);return[A.TextEdit.replace(y.range,O)]}),B}var F={};async function C(){let{parseArgs:b}=await import("node:util"),{createConnection:v}=await Promise.resolve().then(() => _),{values:i}=b({options:{version:{type:"boolean",short:"v"}},strict:!0,allowPositionals:!0});if(i.version)process.stdout.write(Z),process.exit(0);(await v()).listen()}var $=X(()=>{Y();C()});Promise.resolve().then(() => $());
2
+ var C=(i,p,s)=>()=>{if(i)try{p=i(i=0)}catch(r){s=[r]}if(s)throw s[0];return p};var b="0.0.3";var y=()=>{};async function P(){let i=await import("node:path"),{URI:p}=await import("vscode-uri"),{TextDocument:s}=await import("vscode-languageserver-textdocument"),r=await import("vscode-languageserver/node.js"),d=new r.TextDocuments(s),a=r.createConnection(process.stdin,process.stdout);d.listen(a);let f,m,w,c=await import("prettier");async function h(e){try{c=await import(i.join(e,"node_modules","prettier","index.mjs")),a.console.info(`Loaded project prettier from ${e}`)}catch(n){if(n instanceof Error&&"code"in n&&n.code==="ERR_MODULE_NOT_FOUND");else a.console.warn(`Failed to load project prettier from ${e}, falling back to global prettier: ${n}`);c=await import("prettier")}}async function T(e){m??=await c.resolveConfigFile(e),w??=await c.resolveConfig(e,{editorconfig:!0,useCache:!1,...m&&{config:m}})}async function F(e){if(w)return w;return await c.resolveConfig(e,{editorconfig:!0,useCache:!0})}async function x(e,n,t){let o=p.parse(e).fsPath;await h(o);let l=await F(o);return await c.format(n,{...l,...t,filepath:o})}return a.onInitialize(async({workspaceFolders:e})=>{if(f=e?.[0],f)await T(i.join(p.parse(f.uri).fsPath,"_"));return{capabilities:{textDocumentSync:r.TextDocumentSyncKind.Incremental,documentFormattingProvider:!0,documentRangeFormattingProvider:!0}}}),a.onDocumentFormatting(async(e,n)=>{let t=d.get(e.textDocument.uri);if(!t)return null;let o=t.getText(),l={line:0,character:0},u=t.positionAt(o.length),g=r.Range.create(l,u),v=await x(t.uri,o);return[r.TextEdit.replace(g,v)]}),a.onDocumentRangeFormatting(async(e,n)=>{let t=d.get(e.textDocument.uri);if(!t)return null;let o=t.getText(),l=t.offsetAt(e.range.start),u=t.offsetAt(e.range.end),g=await x(t.uri,o,{rangeStart:l,rangeEnd:u}),v=g.slice(l,u+g.length-o.length);return[r.TextEdit.replace(e.range,v)]}),a}async function k(){let{parseArgs:i}=await import("node:util");await Promise.resolve();let{values:s}=i({options:{version:{type:"boolean",short:"v"}},strict:!0,allowPositionals:!0});if(s.version)process.stdout.write(b),process.exit(0);(await P()).listen()}var D=C(()=>{y();k()});Promise.resolve().then(() => D());
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "prettier-language-server",
3
- "type": "module",
4
- "version": "0.0.2",
3
+ "type": "commonjs",
4
+ "version": "0.0.4",
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": ["bin/prettier-language-server"],
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"