Skip to content

Update to fix InvokeAsync usage #1785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions docs/extensibility/adding-an-lsp-extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ The LSP does not include specification on how to provide text colorization for l

4. Create a *.pkgdef* file and add a line similar to this:

```xml
[$RootKey$\TextMate\Repositories]
"MyLang"="$PackageFolder$\Grammars"
```
```xml
[$RootKey$\TextMate\Repositories]
"MyLang"="$PackageFolder$\Grammars"
```

5. Right-click on the files and select **Properties**. Change the **Build** action to **Content** and the **Include in VSIX** property to true.

Expand Down Expand Up @@ -193,7 +193,7 @@ namespace MockLanguageExtension

public async Task OnLoadedAsync()
{
await StartAsync?.InvokeAsync(this, EventArgs.Empty);
await StartAsync.InvokeAsync(this, EventArgs.Empty);
}

public async Task OnServerInitializeFailedAsync(Exception e)
Expand All @@ -207,7 +207,7 @@ namespace MockLanguageExtension
}
}
}
```
```

The main methods that need to be implemented are [OnLoadedAsync](/dotnet/api/microsoft.visualstudio.languageserver.client.ilanguageclient.onloadedasync?view=visualstudiosdk-2017) and [ActivateAsync](/dotnet/api/microsoft.visualstudio.languageserver.client.ilanguageclient.activateasync?view=visualstudiosdk-2017). [OnLoadedAsync](/dotnet/api/microsoft.visualstudio.languageserver.client.ilanguageclient.onloadedasync?view=visualstudiosdk-2017) is called when Visual Studio has loaded your extension and your language server is ready to be started. In this method, you can invoke the [StartAsync](/dotnet/api/microsoft.visualstudio.languageserver.client.ilanguageclient.startasync?view=visualstudiosdk-2017) delegate immediately to signal that the language server should be started, or you can do additional logic and invoke [StartAsync](/dotnet/api/microsoft.visualstudio.languageserver.client.ilanguageclient.startasync?view=visualstudiosdk-2017) later. **To activate your language server, you must call StartAsync at some point.**

Expand All @@ -220,7 +220,7 @@ Once your language client class is implemented, you'll need to define two attrib
```csharp
[Export(typeof(ILanguageClient))]
[ContentType("bar")]
```
```

### MEF

Expand Down Expand Up @@ -263,7 +263,7 @@ namespace MockLanguageExtension
internal static FileExtensionToContentTypeDefinition BarFileExtensionDefinition;
}
}
```
```

In the previous example, a content type definition is created for files that end in *.bar* file extension. The content type definition is given the name "bar" and **must** derive from [CodeRemoteContentTypeName](/dotnet/api/microsoft.visualstudio.languageserver.client.coderemotecontentdefinition.coderemotecontenttypename?view=visualstudiosdk-2017).

Expand All @@ -275,7 +275,7 @@ After adding a content type definition, you can then define when to load your la
public class BarLanguageClient : ILanguageClient
{
}
```
```

Adding support for LSP language servers does not require you to implement your own project system in Visual Studio. Customers can open a single file or a folder in Visual Studio to start using your language service. In fact, support for LSP language servers is designed to work only in open folder/file scenarios. If a custom project system is implemented, some features (such as settings) will not work.

Expand All @@ -289,63 +289,63 @@ Follow these steps below to add support for settings to your LSP language servic

1. Add a JSON file (for example, *MockLanguageExtensionSettings.json*) in your project that contains the settings and their default values. For example:

```json
{
```json
{
"foo.maxNumberOfProblems": -1
}
```
}
```
2. Right-click on the JSON file and select **Properties**. Change the **Build** action to "Content" and the "Include in VSIX' property to true.

3. Implement ConfigurationSections and return the list of prefixes for the settings defined in the JSON file (In Visual Studio Code, this would map to the configuration section name in package.json):

```csharp
public IEnumerable<string> ConfigurationSections
{
```csharp
public IEnumerable<string> ConfigurationSections
{
get
{
yield return "foo";
}
}
```
}
```
4. Add a .pkgdef file to the project (add new text file and change the file extension to .pkgdef). The pkgdef file should contain this info:

```xml
```xml
[$RootKey$\OpenFolder\Settings\VSWorkspaceSettings\[settings-name]]
@="$PackageFolder$\[settings-file-name].json"
```
```

5. Right click on the .pkgdef file and select **Properties**. Change the **Build** action to **Content** and the **Include in VSIX** property to true.

6. Open up the *source.extension.vsixmanifest* file and add an asset in the **Asset** tab:

![edit vspackage asset](media/lsp-add-vspackage-asset.png)
![edit vspackage asset](media/lsp-add-vspackage-asset.png)

* **Type**: Microsoft.VisualStudio.VsPackage
* **Source**: File on filesystem
* **Path**: [Path to your *.pkgdef* file]
* **Type**: Microsoft.VisualStudio.VsPackage
* **Source**: File on filesystem
* **Path**: [Path to your *.pkgdef* file]

### User editing of settings for a workspace

1. User opens a workspace containing files your server owns.
2. User adds a file in the *.vs* folder called *VSWorkspaceSettings.json*.
3. User adds a line to the *VSWorkspaceSettings.json* file for a setting the server provides. For example:

```json
{
```json
{
"foo.maxNumberOfProblems": 10
}
```
### Enabling diagnostics tracing
Diagnostics tracing can be enabled to output all messages between the client and server, which can be useful when debugging issues. To enable diagnostic tracing, do the following:
}
```
### Enabling diagnostics tracing
Diagnostics tracing can be enabled to output all messages between the client and server, which can be useful when debugging issues. To enable diagnostic tracing, do the following:

4. Open or create the workspace settings file *VSWorkspaceSettings.json* (see "User editing of settings for a workspace").
5. Add the following line in the settings json file:
4. Open or create the workspace settings file *VSWorkspaceSettings.json* (see "User editing of settings for a workspace").
5. Add the following line in the settings json file:

```json
{
"foo.trace.server": "Off"
}
```
```

There are three possible values for trace verbosity:
* "Off": tracing turned off completely
Expand Down Expand Up @@ -391,7 +391,7 @@ internal class MockCustomLanguageClient : MockLanguageClient, ILanguageClientCus
}
}
}
```
```

#### Sending custom messages

Expand Down Expand Up @@ -424,7 +424,7 @@ internal class MockCustomLanguageClient : MockLanguageClient, ILanguageClientCus
return await this.customMessageRpc.InvokeAsync<string>("OnCustomRequest", test);
}
}
```
```

### Middle layer

Expand Down Expand Up @@ -455,7 +455,7 @@ public class MockLanguageClient: ILanguageClient, ILanguageClientCustomMessage
}
}
}
```
```

The middle layer feature is still under development and not yet comprehensive.

Expand Down