rintenki-lsp-server 0.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-PRESENT Kazuhiro Kobayashi<https://github.com/kzhrk>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ export {};
package/dist/server.js ADDED
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const node_js_1 = require("vscode-languageserver/node.js");
4
+ const vscode_languageserver_textdocument_1 = require("vscode-languageserver-textdocument");
5
+ const rintenki_1 = require("rintenki");
6
+ const connection = (0, node_js_1.createConnection)(node_js_1.ProposedFeatures.all);
7
+ const documents = new node_js_1.TextDocuments(vscode_languageserver_textdocument_1.TextDocument);
8
+ let config;
9
+ connection.onInitialize((_params) => {
10
+ return {
11
+ capabilities: {
12
+ textDocumentSync: node_js_1.TextDocumentSyncKind.Full,
13
+ codeActionProvider: {
14
+ codeActionKinds: [node_js_1.CodeActionKind.QuickFix],
15
+ },
16
+ },
17
+ };
18
+ });
19
+ connection.onInitialized(() => {
20
+ connection.workspace.getConfiguration("rintenki").then((settings) => {
21
+ if (settings?.rules) {
22
+ config = { rules: settings.rules };
23
+ }
24
+ }, () => {
25
+ // Configuration not available, use defaults
26
+ });
27
+ });
28
+ connection.onDidChangeConfiguration((_change) => {
29
+ connection.workspace.getConfiguration("rintenki").then((settings) => {
30
+ if (settings?.rules) {
31
+ config = { rules: settings.rules };
32
+ }
33
+ else {
34
+ config = undefined;
35
+ }
36
+ documents.all().forEach(validateDocument);
37
+ }, () => {
38
+ // Configuration not available, use defaults
39
+ });
40
+ });
41
+ documents.onDidChangeContent((change) => {
42
+ validateDocument(change.document);
43
+ });
44
+ function toDiagnosticSeverity(severity) {
45
+ return severity === "error"
46
+ ? node_js_1.DiagnosticSeverity.Error
47
+ : node_js_1.DiagnosticSeverity.Warning;
48
+ }
49
+ function toLspDiagnostic(d) {
50
+ const line = Math.max((d.line ?? 1) - 1, 0);
51
+ return {
52
+ range: {
53
+ start: { line, character: 0 },
54
+ end: { line, character: Number.MAX_SAFE_INTEGER },
55
+ },
56
+ severity: toDiagnosticSeverity(d.severity),
57
+ source: "rintenki",
58
+ code: d.rule,
59
+ message: d.message,
60
+ data: { fixable: d.fixable },
61
+ };
62
+ }
63
+ function validateDocument(document) {
64
+ if (document.languageId !== "html") {
65
+ return;
66
+ }
67
+ const text = document.getText();
68
+ const result = (0, rintenki_1.lint)(text, config);
69
+ const diagnostics = result.diagnostics.map(toLspDiagnostic);
70
+ connection.sendDiagnostics({ uri: document.uri, diagnostics });
71
+ }
72
+ connection.onCodeAction((params) => {
73
+ const document = documents.get(params.textDocument.uri);
74
+ if (!document)
75
+ return [];
76
+ const fixableDiagnostics = params.context.diagnostics.filter((d) => d.source === "rintenki" && d.data?.fixable);
77
+ if (fixableDiagnostics.length === 0)
78
+ return [];
79
+ const text = document.getText();
80
+ const fixResult = (0, rintenki_1.fix)(text, config);
81
+ if (fixResult.fixedCount === 0)
82
+ return [];
83
+ const lastLine = Math.max(document.lineCount - 1, 0);
84
+ return [
85
+ {
86
+ title: "Fix all auto-fixable rintenki issues",
87
+ kind: node_js_1.CodeActionKind.QuickFix,
88
+ diagnostics: fixableDiagnostics,
89
+ edit: {
90
+ changes: {
91
+ [params.textDocument.uri]: [
92
+ node_js_1.TextEdit.replace({
93
+ start: { line: 0, character: 0 },
94
+ end: { line: lastLine, character: Number.MAX_SAFE_INTEGER },
95
+ }, fixResult.output),
96
+ ],
97
+ },
98
+ },
99
+ },
100
+ ];
101
+ });
102
+ documents.listen(connection);
103
+ connection.listen();
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "rintenki-lsp-server",
3
+ "version": "0.0.0",
4
+ "description": "LSP server for rintenki HTML linter",
5
+ "author": "Kazuhiro Kobayashi <https://github.com/kzhrk>",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/kzhrk/rintenki",
10
+ "directory": "packages/rintenki-lsp-server"
11
+ },
12
+ "homepage": "https://github.com/kzhrk/rintenki",
13
+ "bugs": {
14
+ "url": "https://github.com/kzhrk/rintenki/issues"
15
+ },
16
+ "keywords": [
17
+ "html",
18
+ "linter",
19
+ "lsp",
20
+ "language-server"
21
+ ],
22
+ "main": "dist/server.js",
23
+ "dependencies": {
24
+ "vscode-languageserver": "9.0.1",
25
+ "vscode-languageserver-textdocument": "1.0.12",
26
+ "rintenki": "0.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "typescript": "6.0.2"
30
+ },
31
+ "scripts": {
32
+ "build": "tsc",
33
+ "watch": "tsc --watch"
34
+ }
35
+ }
package/src/server.ts ADDED
@@ -0,0 +1,138 @@
1
+ import {
2
+ createConnection,
3
+ TextDocuments,
4
+ ProposedFeatures,
5
+ InitializeParams,
6
+ InitializeResult,
7
+ TextDocumentSyncKind,
8
+ Diagnostic,
9
+ DiagnosticSeverity,
10
+ CodeAction,
11
+ CodeActionKind,
12
+ TextEdit,
13
+ CodeActionParams,
14
+ } from "vscode-languageserver/node.js";
15
+ import { TextDocument } from "vscode-languageserver-textdocument";
16
+ import { lint, fix, type LintConfig, type LintDiagnostic } from "rintenki";
17
+
18
+ const connection = createConnection(ProposedFeatures.all);
19
+ const documents = new TextDocuments(TextDocument);
20
+
21
+ let config: LintConfig | undefined;
22
+
23
+ connection.onInitialize((_params: InitializeParams): InitializeResult => {
24
+ return {
25
+ capabilities: {
26
+ textDocumentSync: TextDocumentSyncKind.Full,
27
+ codeActionProvider: {
28
+ codeActionKinds: [CodeActionKind.QuickFix],
29
+ },
30
+ },
31
+ };
32
+ });
33
+
34
+ connection.onInitialized(() => {
35
+ connection.workspace.getConfiguration("rintenki").then(
36
+ (settings) => {
37
+ if (settings?.rules) {
38
+ config = { rules: settings.rules };
39
+ }
40
+ },
41
+ () => {
42
+ // Configuration not available, use defaults
43
+ }
44
+ );
45
+ });
46
+
47
+ connection.onDidChangeConfiguration((_change) => {
48
+ connection.workspace.getConfiguration("rintenki").then(
49
+ (settings) => {
50
+ if (settings?.rules) {
51
+ config = { rules: settings.rules };
52
+ } else {
53
+ config = undefined;
54
+ }
55
+ documents.all().forEach(validateDocument);
56
+ },
57
+ () => {
58
+ // Configuration not available, use defaults
59
+ }
60
+ );
61
+ });
62
+
63
+ documents.onDidChangeContent((change) => {
64
+ validateDocument(change.document);
65
+ });
66
+
67
+ function toDiagnosticSeverity(severity: string): DiagnosticSeverity {
68
+ return severity === "error"
69
+ ? DiagnosticSeverity.Error
70
+ : DiagnosticSeverity.Warning;
71
+ }
72
+
73
+ function toLspDiagnostic(d: LintDiagnostic): Diagnostic {
74
+ const line = Math.max((d.line ?? 1) - 1, 0);
75
+ return {
76
+ range: {
77
+ start: { line, character: 0 },
78
+ end: { line, character: Number.MAX_SAFE_INTEGER },
79
+ },
80
+ severity: toDiagnosticSeverity(d.severity),
81
+ source: "rintenki",
82
+ code: d.rule,
83
+ message: d.message,
84
+ data: { fixable: d.fixable },
85
+ };
86
+ }
87
+
88
+ function validateDocument(document: TextDocument): void {
89
+ if (document.languageId !== "html") {
90
+ return;
91
+ }
92
+
93
+ const text = document.getText();
94
+ const result = lint(text, config);
95
+ const diagnostics = result.diagnostics.map(toLspDiagnostic);
96
+ connection.sendDiagnostics({ uri: document.uri, diagnostics });
97
+ }
98
+
99
+ connection.onCodeAction((params: CodeActionParams): CodeAction[] => {
100
+ const document = documents.get(params.textDocument.uri);
101
+ if (!document) return [];
102
+
103
+ const fixableDiagnostics = params.context.diagnostics.filter(
104
+ (d) => d.source === "rintenki" && (d.data as any)?.fixable
105
+ );
106
+
107
+ if (fixableDiagnostics.length === 0) return [];
108
+
109
+ const text = document.getText();
110
+ const fixResult = fix(text, config);
111
+
112
+ if (fixResult.fixedCount === 0) return [];
113
+
114
+ const lastLine = Math.max(document.lineCount - 1, 0);
115
+ return [
116
+ {
117
+ title: "Fix all auto-fixable rintenki issues",
118
+ kind: CodeActionKind.QuickFix,
119
+ diagnostics: fixableDiagnostics,
120
+ edit: {
121
+ changes: {
122
+ [params.textDocument.uri]: [
123
+ TextEdit.replace(
124
+ {
125
+ start: { line: 0, character: 0 },
126
+ end: { line: lastLine, character: Number.MAX_SAFE_INTEGER },
127
+ },
128
+ fixResult.output
129
+ ),
130
+ ],
131
+ },
132
+ },
133
+ },
134
+ ];
135
+ });
136
+
137
+ documents.listen(connection);
138
+ connection.listen();
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "outDir": "dist",
7
+ "rootDir": "src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "declaration": true,
11
+ "skipLibCheck": true
12
+ },
13
+ "include": ["src"],
14
+ "exclude": ["node_modules", "dist"]
15
+ }