MCPcopy
hub / github.com/APKLab/APKLab / startServer

Function startServer

src/tools/smali-lsp.ts:60–157  ·  view source on GitHub ↗
(document: TextDocument)

Source from the content-addressed store, hash-verified

58 * Start the Smali LSP server for the given document's project.
59 */
60 export async function startServer(document: TextDocument): Promise<void> {
61 if (client) return;
62
63 const projectRoot = findApktoolProjectRoot(
64 path.dirname(document.uri.fsPath),
65 );
66 if (!projectRoot) {
67 outputChannel.appendLine(
68 "Smali LSP: No APKTool project found (no apktool.yml in parent dirs)",
69 );
70 return;
71 }
72
73 const javaPath = getJavaPath();
74 const serverJar = resolveServerJar();
75 if (!serverJar) {
76 window.showWarningMessage(
77 "APKLab: Smali LSP server JAR not found. Use 'APKLab: Update Tools' to trigger download, or set apklab.smaliLspPath.",
78 );
79 return;
80 }
81
82 outputChannel.appendLine(
83 `Smali LSP: Starting for project ${projectRoot}`,
84 );
85 outputChannel.appendLine(` Java: ${javaPath}`);
86 outputChannel.appendLine(` Server: ${serverJar}`);
87
88 const serverOptions: ServerOptions = {
89 command: javaPath,
90 args: ["-jar", serverJar, "lsp"],
91 };
92
93 const clientOptions: LanguageClientOptions = {
94 documentSelector: [{ scheme: "file", language: "smali" }],
95 synchronize: {
96 fileEvents: workspace.createFileSystemWatcher("**/*.smali"),
97 },
98 outputChannel: outputChannel,
99 revealOutputChannelOn: 4, // Never
100 workspaceFolder: {
101 uri: Uri.file(projectRoot),
102 name: path.basename(projectRoot),
103 index: 0,
104 },
105 middleware: {
106 handleWorkDoneProgress: (_token, params, next) => {
107 if ("kind" in params) {
108 if (
109 params.kind === "begin" ||
110 params.kind === "report"
111 ) {
112 const pct =
113 params.percentage !== undefined
114 ? ` ${params.percentage}%`
115 : "";
116 const msg = params.message
117 ? ` (${params.message})`

Callers 1

registerFunction · 0.85

Calls 5

getJavaPathFunction · 0.90
findApktoolProjectRootFunction · 0.85
resolveServerJarFunction · 0.85
showStatusBarFunction · 0.85
updateStatusBarFunction · 0.85

Tested by

no test coverage detected