rintenki-lsp-server 0.2.0 → 0.4.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.
Files changed (2) hide show
  1. package/dist/server.js +62 -22
  2. package/package.json +2 -2
package/dist/server.js CHANGED
@@ -28,6 +28,8 @@ connection.onInitialized(() => {
28
28
  if (settings?.rules) {
29
29
  config = { rules: settings.rules };
30
30
  }
31
+ // Re-validate all open documents after config is loaded
32
+ documents.all().forEach(validateDocument);
31
33
  }, () => {
32
34
  // Configuration not available, use defaults
33
35
  });
@@ -55,19 +57,31 @@ function toDiagnosticSeverity(severity) {
55
57
  }
56
58
  function toLspDiagnostic(d) {
57
59
  const line = Math.max((d.line ?? 1) - 1, 0);
60
+ const startChar = d.col ?? 0;
61
+ const endLine = d.endLine != null ? Math.max(d.endLine - 1, 0) : line;
62
+ const endChar = d.endCol ?? Number.MAX_SAFE_INTEGER;
58
63
  return {
59
64
  range: {
60
- start: { line, character: 0 },
61
- end: { line, character: Number.MAX_SAFE_INTEGER },
65
+ start: { line, character: startChar },
66
+ end: { line: endLine, character: endChar },
62
67
  },
63
68
  severity: toDiagnosticSeverity(d.severity),
64
69
  source: "rintenki",
65
70
  code: d.rule,
66
- message: d.message,
71
+ message: d.hint ? `${d.message}\nhint: ${d.hint}` : d.message,
67
72
  data: { fixable: d.fixable },
68
73
  };
69
74
  }
70
75
  const SUPPORTED_LANGUAGES = ["html", "vue", "erb", "javascriptreact", "typescriptreact"];
76
+ const FIXABLE_RULES = [
77
+ "case-sensitive-tag-name",
78
+ "case-sensitive-attr-name",
79
+ "attr-value-quotes",
80
+ "no-boolean-attr-value",
81
+ "no-default-value",
82
+ "character-reference",
83
+ "doctype",
84
+ ];
71
85
  function validateDocument(document) {
72
86
  if (!SUPPORTED_LANGUAGES.includes(document.languageId)) {
73
87
  return;
@@ -93,6 +107,8 @@ function validateDocument(document) {
93
107
  for (const d of result.diagnostics) {
94
108
  if (d.line != null)
95
109
  d.line += lineOffset;
110
+ if (d.endLine != null)
111
+ d.endLine += lineOffset;
96
112
  }
97
113
  }
98
114
  const diagnostics = result.diagnostics.map(toLspDiagnostic);
@@ -106,27 +122,51 @@ connection.onCodeAction((params) => {
106
122
  if (fixableDiagnostics.length === 0)
107
123
  return [];
108
124
  const text = document.getText();
109
- const fixResult = (0, rintenki_1.fix)(text, config);
110
- if (fixResult.fixedCount === 0)
111
- return [];
112
125
  const lastLine = Math.max(document.lineCount - 1, 0);
113
- return [
114
- {
115
- title: "Fix all auto-fixable rintenki issues",
116
- kind: node_js_1.CodeActionKind.QuickFix,
117
- diagnostics: fixableDiagnostics,
118
- edit: {
119
- changes: {
120
- [params.textDocument.uri]: [
121
- node_js_1.TextEdit.replace({
122
- start: { line: 0, character: 0 },
123
- end: { line: lastLine, character: Number.MAX_SAFE_INTEGER },
124
- }, fixResult.output),
125
- ],
126
+ const fullRange = {
127
+ start: { line: 0, character: 0 },
128
+ end: { line: lastLine, character: Number.MAX_SAFE_INTEGER },
129
+ };
130
+ const actions = [];
131
+ // Per-rule Quick Fix actions
132
+ const ruleNames = [...new Set(fixableDiagnostics.map((d) => d.code))];
133
+ for (const rule of ruleNames) {
134
+ const ruleDiagnostics = fixableDiagnostics.filter((d) => d.code === rule);
135
+ // Create a config that only enables this specific rule for fixing
136
+ const ruleOnlyConfig = {
137
+ rules: Object.fromEntries(FIXABLE_RULES.map((r) => [r, r === rule ? (config?.rules?.[r] ?? true) : "off"])),
138
+ };
139
+ const fixResult = (0, rintenki_1.fix)(text, ruleOnlyConfig);
140
+ if (fixResult.fixedCount > 0) {
141
+ actions.push({
142
+ title: `Fix: ${rule}`,
143
+ kind: node_js_1.CodeActionKind.QuickFix,
144
+ diagnostics: ruleDiagnostics,
145
+ edit: {
146
+ changes: {
147
+ [params.textDocument.uri]: [node_js_1.TextEdit.replace(fullRange, fixResult.output)],
148
+ },
126
149
  },
127
- },
128
- },
129
- ];
150
+ });
151
+ }
152
+ }
153
+ // Fix all action
154
+ if (ruleNames.length > 1) {
155
+ const fixResult = (0, rintenki_1.fix)(text, config);
156
+ if (fixResult.fixedCount > 0) {
157
+ actions.push({
158
+ title: "Fix all auto-fixable rintenki issues",
159
+ kind: node_js_1.CodeActionKind.QuickFix,
160
+ diagnostics: fixableDiagnostics,
161
+ edit: {
162
+ changes: {
163
+ [params.textDocument.uri]: [node_js_1.TextEdit.replace(fullRange, fixResult.output)],
164
+ },
165
+ },
166
+ });
167
+ }
168
+ }
169
+ return actions;
130
170
  });
131
171
  documents.listen(connection);
132
172
  connection.listen();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rintenki-lsp-server",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "LSP server for rintenki HTML linter",
5
5
  "author": "Kazuhiro Kobayashi <https://github.com/kzhrk>",
6
6
  "license": "MIT",
@@ -26,7 +26,7 @@
26
26
  "dependencies": {
27
27
  "vscode-languageserver": "9.0.1",
28
28
  "vscode-languageserver-textdocument": "1.0.12",
29
- "rintenki": "0.2.0"
29
+ "rintenki": "0.4.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "typescript": "6.0.2"