-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: Tristan Partin <tristan@partin.io>
- Loading branch information
1 parent
6212905
commit 8bd8c7c
Showing
9 changed files
with
619 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as vscode from "vscode"; | ||
import { LanguageServerClient } from "."; | ||
import { LanguageServer } from "../types"; | ||
import { SwiftMesonLspLanguageClient } from "./swift-mesonlsp"; | ||
import { Uri } from "vscode"; | ||
|
||
export async function createLanguageServerClient( | ||
server: LanguageServer, | ||
download: boolean, | ||
context: vscode.ExtensionContext, | ||
): Promise<LanguageServerClient | null> { | ||
const serverToClass = (server: LanguageServer) => { | ||
switch (server) { | ||
case "Swift-MesonLSP": | ||
return SwiftMesonLspLanguageClient; | ||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
const klass = serverToClass(server); | ||
if (klass == null) { | ||
return null; | ||
} | ||
if (!klass.supportsSystem()) { | ||
vscode.window.showErrorMessage("The configured language server does not support the current system."); | ||
return null; | ||
} | ||
|
||
let languageServerPath = LanguageServerClient.resolveLanguageServerPath(server, context); | ||
if (languageServerPath === null) { | ||
if (klass.artifact() == null) { | ||
enum Options { | ||
open = "Open documentation in browser", | ||
} | ||
const response = await vscode.window.showErrorMessage( | ||
"This language server supports your systen, but provides no artifacts for automatic setup", | ||
...Object.values(Options), | ||
); | ||
if (response == Options.open) { | ||
vscode.env.openExternal(Uri.parse(klass.setupURL)); | ||
} | ||
return null; | ||
} | ||
if (download) { | ||
languageServerPath = await klass.download(server, klass.version, context); | ||
if (languageServerPath === null) { | ||
vscode.window.showErrorMessage("Failed to download the language server."); | ||
return null; | ||
} | ||
} else { | ||
vscode.window.showErrorMessage("Failed to find a language server on the system."); | ||
return null; | ||
} | ||
} | ||
|
||
return new klass(languageServerPath, context); | ||
} |
Oops, something went wrong.