-
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.
- Loading branch information
Showing
7 changed files
with
424 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as which from "which"; | ||
import { | ||
canDownloadLanguageServer, | ||
findLanguageServer, | ||
setupLanguageServer, | ||
} from "./utils"; | ||
import { ExtensionContext, WorkspaceConfiguration, workspace } from "vscode"; | ||
import { LanguageClient } from "vscode-languageclient/node"; | ||
|
||
export abstract class LanguageServerClient { | ||
config: WorkspaceConfiguration | ||
ls: LanguageClient | null = null | ||
executableName: string | ||
context: ExtensionContext | ||
|
||
constructor(executableName: string, context: ExtensionContext) { | ||
this.executableName = executableName | ||
this.context = context | ||
this.config = workspace.getConfiguration("mesonbuild"); | ||
const serverModule = this.languageServerPath; | ||
|
||
if (serverModule == null) | ||
return; | ||
this.startLanguageServer(serverModule); | ||
} | ||
|
||
abstract startLanguageServer(serverModule: string): void | ||
|
||
abstract get downloadInfo(): [url: string, hash: string] | null; | ||
|
||
restart(): void { | ||
this.dispose(); | ||
const serverModule = this.languageServerPath; | ||
|
||
if (serverModule == null) | ||
return; | ||
this.startLanguageServer(serverModule); | ||
} | ||
|
||
canDownloadLanguageServer(): boolean { | ||
return canDownloadLanguageServer(this) | ||
} | ||
|
||
get languageServerPath(): string | null { | ||
return findLanguageServer(this) || this.config.languageServerPath || which.sync(this.executableName, { nothrow: true }) | ||
} | ||
|
||
async setupLanguageServer() { | ||
setupLanguageServer(this) | ||
} | ||
|
||
dispose() { | ||
if (this.ls) { | ||
this.ls.stop() | ||
|
||
this.ls = null | ||
} | ||
} | ||
} |
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,60 @@ | ||
import * as os from "os"; | ||
|
||
import { | ||
LanguageClient, | ||
LanguageClientOptions, | ||
ServerOptions, | ||
Executable, | ||
TransportKind | ||
} from "vscode-languageclient/node"; | ||
import { | ||
ExtensionContext, | ||
} from "vscode" | ||
import { LanguageServerClient } from "../lsp"; | ||
|
||
export class SwiftMesonLspLanguageClient extends LanguageServerClient { | ||
ls: LanguageClient | null = null | ||
|
||
constructor(ctx: ExtensionContext) { | ||
super("Swift-MesonLSP", ctx); | ||
} | ||
|
||
get downloadInfo(): [url: string, hash: string] | null { | ||
const platform = os.platform(); | ||
if (platform != "win32" && platform != "darwin") { | ||
return null; | ||
} | ||
const arch = os.arch(); | ||
if (arch != "x64") { | ||
return null; | ||
} | ||
if (platform == "win32") | ||
return ["https://github.com/JCWasmx86/Swift-MesonLSP/releases/download/v2.0/Swift-MesonLSP-win64.zip", | ||
"fc0d930eb67525309291907c07df8655920cdc651f17f2320d09cc5271a23876"] | ||
return ["https://github.com/JCWasmx86/Swift-MesonLSP/releases/download/v2.0/Swift-MesonLSP-macos12.zip", | ||
"c10999081cef8b56ea164d9a170470c268045254829e48bf4ac137a07a8a874c"] | ||
} | ||
|
||
startLanguageServer(serverModule: string): void { | ||
const clientOptions: LanguageClientOptions = { | ||
documentSelector: ["meson", { "scheme": "file", language: "meson" }] | ||
}; | ||
|
||
const runExe: Executable = { | ||
command: serverModule, | ||
args: ["--lsp"], | ||
}; | ||
const debugExe: Executable = { | ||
command: serverModule, | ||
args: ["--lsp"], | ||
}; | ||
const serverOptions: ServerOptions = { | ||
run: runExe, | ||
debug: debugExe, | ||
transport: TransportKind.stdio | ||
}; | ||
|
||
this.ls = new LanguageClient("Swift-MesonLSP", "Meson Language Server", serverOptions, clientOptions, true); | ||
this.ls.start(); | ||
} | ||
} |
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
Oops, something went wrong.