@spyglassmc/language-server 0.4.25 → 0.4.27

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/lib/server.js CHANGED
@@ -95,6 +95,7 @@ connection.onInitialize(async (params) => {
95
95
  const ans = {
96
96
  serverInfo: { name: 'Spyglass Language Server' },
97
97
  capabilities: {
98
+ codeActionProvider: {},
98
99
  colorProvider: {},
99
100
  completionProvider: { triggerCharacters: service.project.meta.getTriggerCharacters() },
100
101
  declarationProvider: {},
@@ -146,6 +147,15 @@ connection.onDidCloseTextDocument(({ textDocument: { uri } }) => {
146
147
  service.project.onDidClose(uri);
147
148
  });
148
149
  connection.workspace.onDidRenameFiles(({}) => { });
150
+ connection.onCodeAction(async ({ textDocument: { uri }, range }) => {
151
+ const docAndNode = await service.project.ensureClientManagedChecked(uri);
152
+ if (!docAndNode) {
153
+ return undefined;
154
+ }
155
+ const { doc, node } = docAndNode;
156
+ const codeActions = service.getCodeActions(node, doc, toCore.range(range, doc));
157
+ return codeActions.map(a => toLS.codeAction(a, doc));
158
+ });
149
159
  connection.onColorPresentation(async ({ textDocument: { uri }, color, range }) => {
150
160
  const docAndNode = await service.project.ensureClientManagedChecked(uri);
151
161
  if (!docAndNode) {
@@ -18,6 +18,7 @@ export declare function documentSymbolsFromTables(tables: core.SymbolTable[], do
18
18
  export declare function hover(hover: core.Hover, doc: TextDocument): ls.Hover;
19
19
  export declare function inlayHint(hint: core.InlayHint, doc: TextDocument): ls.InlayHint;
20
20
  export declare function inlayHints(hints: core.InlayHint[], doc: TextDocument): ls.InlayHint[];
21
+ export declare function codeAction(codeAction: core.CodeAction, doc: TextDocument): ls.CodeAction;
21
22
  export declare function completionItem(completion: core.CompletionItem, doc: TextDocument, requestedOffset: number, insertReplaceSupport: boolean | undefined): ls.CompletionItem;
22
23
  export declare function location(location: {
23
24
  uri: string;
package/lib/util/toLS.js CHANGED
@@ -113,6 +113,32 @@ export function inlayHint(hint, doc) {
113
113
  export function inlayHints(hints, doc) {
114
114
  return hints.map((h) => inlayHint(h, doc));
115
115
  }
116
+ export function codeAction(codeAction, doc) {
117
+ return {
118
+ title: codeAction.title,
119
+ kind: ls.CodeActionKind.QuickFix,
120
+ isPreferred: codeAction.isPreferred,
121
+ diagnostics: codeAction.errors?.map(e => diagnostic(core.LanguageError.withPosRange(e, doc))),
122
+ edit: codeAction.changes
123
+ ? {
124
+ documentChanges: codeAction.changes.map(change => {
125
+ switch (change.type) {
126
+ case 'edit':
127
+ return {
128
+ textDocument: { uri: doc.uri, version: doc.version },
129
+ edits: [{ range: range(change.range, doc), newText: change.text }],
130
+ };
131
+ case 'create':
132
+ return {
133
+ kind: 'create',
134
+ uri: change.uri,
135
+ };
136
+ }
137
+ }),
138
+ }
139
+ : undefined,
140
+ };
141
+ }
116
142
  export function completionItem(completion, doc, requestedOffset, insertReplaceSupport) {
117
143
  const insertText = completion.insertText ?? completion.label;
118
144
  const canInsertReplace = insertReplaceSupport
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spyglassmc/language-server",
3
- "version": "0.4.25",
3
+ "version": "0.4.27",
4
4
  "type": "module",
5
5
  "main": "lib/server.js",
6
6
  "types": "lib/server.d.ts",
@@ -21,10 +21,10 @@
21
21
  "env-paths": "^2.2.1",
22
22
  "vscode-languageserver": "^9.0.1",
23
23
  "vscode-languageserver-textdocument": "^1.0.11",
24
- "@spyglassmc/core": "0.4.20",
25
- "@spyglassmc/java-edition": "0.3.26",
26
- "@spyglassmc/locales": "0.3.11",
27
- "@spyglassmc/mcdoc": "0.3.24"
24
+ "@spyglassmc/core": "0.4.21",
25
+ "@spyglassmc/java-edition": "0.3.27",
26
+ "@spyglassmc/locales": "0.3.12",
27
+ "@spyglassmc/mcdoc": "0.3.25"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public"