miniscript-languageserver 1.5.6 → 1.6.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 (3) hide show
  1. package/README.md +115 -0
  2. package/index.js +69 -69
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -46,6 +46,7 @@ This section provides a collection of IDEs that implement the `miniscript-langua
46
46
  - [Sublime Text](#sublime): Instructions for integrating with Sublime Text.
47
47
  - [IntelliJ](#intellij): Guide for using `miniscript-languageserver` with IntelliJ.
48
48
  - [Neovim (nvim)](#nvim): Configuration for Neovim users.
49
+ - [Visual Studio](#visual-studio): Learn how to set up a Visual Studio extension using LSP to add support for the MiniScript language in Visual Studio.
49
50
 
50
51
  Any other IDEs that follow the [LSP standards](https://code.visualstudio.com/api/language-extensions/language-server-extension-guide) should also work with `miniscript-languageserver`.
51
52
 
@@ -184,6 +185,120 @@ autocmd BufRead,BufNewFile *.src set filetype=src
184
185
 
185
186
  This configuration ensures that miniscript-languageserver will be properly integrated into Neovim, and that .src files will be recognized with the correct syntax highlighting and LSP features.
186
187
 
188
+ #### Visual Studio
189
+
190
+ 1. Begin by following the [official Visual Studio Extensibility Tutorial](https://learn.microsoft.com/de-de/visualstudio/extensibility/adding-an-lsp-extension?view=vs-2022#get-started) to create a new Visual Studio extension. This will set up the basic structure for the extension project.
191
+ 2. In this step, we define a custom content type for the language we are adding (e.g., MiniScript). This will help Visual Studio identify files based on their extension or content type. Create a new class called ContentTypeDefinitions.cs:
192
+ ```csharp
193
+ using Microsoft.VisualStudio.LanguageServer.Client;
194
+ using Microsoft.VisualStudio.Utilities;
195
+ using System.ComponentModel.Composition;
196
+
197
+ namespace MiniScript
198
+ {
199
+ internal static class MiniScriptContentDefinition
200
+ {
201
+ [Export]
202
+ [Name("miniscript")]
203
+ [BaseDefinition(CodeRemoteContentDefinition.CodeRemoteContentTypeName)]
204
+ public static ContentTypeDefinition MiniScriptContentTypeDefinition;
205
+
206
+ [Export]
207
+ [FileExtension(".ms")]
208
+ [ContentType("miniscript")]
209
+ public static FileExtensionToContentTypeDefinition MiniScriptFileExtensionDefinition;
210
+ }
211
+ }
212
+ ```
213
+ 3. Next, you will create the LanguageClient.cs class that connects Visual Studio to the language server. This class implements ILanguageClient, which is essential for interacting with the LSP. Create a new file called LanguageClient.cs:
214
+ ```csharp
215
+ using Microsoft.VisualStudio.LanguageServer.Client;
216
+ using Microsoft.VisualStudio.Threading;
217
+ using Microsoft.VisualStudio.Utilities;
218
+ using System;
219
+ using System.Collections.Generic;
220
+ using System.ComponentModel.Composition;
221
+ using System.Diagnostics;
222
+ using System.Threading;
223
+ using System.Threading.Tasks;
224
+
225
+ namespace MiniScript
226
+ {
227
+ [Export(typeof(ILanguageClient))]
228
+ [ContentType("miniscript")]
229
+ [RunOnContext(RunningContext.RunOnHost)]
230
+ public class MiniScriptLanguageClient : ILanguageClient
231
+ {
232
+ public event AsyncEventHandler<EventArgs> StartAsync;
233
+ public event AsyncEventHandler<EventArgs> StopAsync;
234
+ public object InitializationOptions => null;
235
+ public IEnumerable<string> FilesToWatch => null;
236
+ public bool ShowNotificationOnInitializeFailed => true;
237
+ public string Name => "MiniScript Language Client";
238
+ public IEnumerable<string> ConfigurationSections => new[] { "miniscript" };
239
+
240
+ public Task<Connection> ActivateAsync(CancellationToken token)
241
+ {
242
+ var info = new ProcessStartInfo
243
+ {
244
+ FileName = @"C:\Users\myUser\AppData\Roaming\npm\miniscript-languageserver.cmd",
245
+ Arguments = "--stdio",
246
+ RedirectStandardInput = true,
247
+ RedirectStandardOutput = true,
248
+ UseShellExecute = false,
249
+ CreateNoWindow = true
250
+ };
251
+ var process = new Process { StartInfo = info };
252
+
253
+ if (process.Start())
254
+ {
255
+ Debug.WriteLine("Language server started successfully.");
256
+ return Task.FromResult(new Connection(process.StandardOutput.BaseStream, process.StandardInput.BaseStream));
257
+ }
258
+
259
+ Debug.WriteLine("Failed to start language server.");
260
+ return Task.FromResult<Connection>(null);
261
+ }
262
+
263
+ public async Task OnLoadedAsync()
264
+ {
265
+ if (StartAsync != null)
266
+ {
267
+ await StartAsync.InvokeAsync(this, EventArgs.Empty);
268
+ }
269
+ }
270
+
271
+ public async Task StopServerAsync()
272
+ {
273
+ if (StopAsync != null)
274
+ {
275
+ await StopAsync.InvokeAsync(this, EventArgs.Empty);
276
+ }
277
+ }
278
+
279
+ public Task OnServerInitializedAsync()
280
+ {
281
+ return Task.CompletedTask;
282
+ }
283
+
284
+ public Task<InitializationFailureContext> OnServerInitializeFailedAsync(ILanguageClientInitializationInfo initializationState)
285
+ {
286
+ string message = "MiniScript failed to activate, now we can't test LSP! :(";
287
+ string exception = initializationState.InitializationException?.ToString() ?? string.Empty;
288
+ message = $"{message}\n {exception}";
289
+
290
+ var failureContext = new InitializationFailureContext()
291
+ {
292
+ FailureMessage = message,
293
+ };
294
+
295
+ return Task.FromResult(failureContext);
296
+ }
297
+ }
298
+ }
299
+ ```
300
+ 4. At this point, you have a basic framework for integrating a custom language server into Visual Studio. You can customize the content type, server activation, or extend the language client.
301
+
187
302
  ## How to Add Tooltips
188
303
 
189
304
  Tooltips in `miniscript-languageserver` can help provide additional context, such as method descriptions, to users. You can contribute your own tooltips by following this workflow: