• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import { LspDriverHelper } from './driver_helper';
17import { global } from './global';
18import {
19  LspDefinitionData,
20  LspDiagsNode,
21  LspReferences,
22  LspQuickInfo,
23  LspClassHierarchy,
24  LspCompletionEntryKind,
25  LspClassPropertyInfo,
26  LspClassHierarchies,
27  LspDocumentHighlightsReferences,
28  LspCompletionInfo,
29  LspReferenceLocationList,
30  LspLineAndCharacter,
31  LspReferenceData,
32  LspClassConstructorInfo,
33  ApplicableRefactorItemInfo,
34  LspApplicableRefactorInfo,
35  CompletionEntryDetails,
36  LspFileTextChanges,
37  LspSafeDeleteLocationInfo,
38  LspSafeDeleteLocation,
39  LspTypeHierarchiesInfo,
40  LspTextSpan,
41  LspInlayHint,
42  LspInlayHintList,
43  TextSpan,
44  LspSignatureHelpItems,
45  CodeFixActionInfo,
46  CodeFixActionInfoList
47} from './lspNode';
48import { passStringArray, unpackString } from './private';
49import { Es2pandaContextState } from './generated/Es2pandaEnums';
50import { BuildConfig } from './types';
51import { PluginDriver, PluginHook } from './ui_plugins_driver';
52import { ModuleDescriptor } from './buildConfigGenerate';
53import { generateArkTsConfigByModules } from './arktsConfigGenerate';
54
55import * as fs from 'fs';
56import * as path from 'path';
57
58const ets2pandaCmdPrefix = ['-', '--extension', 'ets', '--arktsconfig'];
59
60function initBuildEnv(): void {
61  const currentPath: string | undefined = process.env.PATH;
62  let pandaLibPath: string = path.resolve(__dirname, '../../ets2panda/lib');
63  process.env.PATH = `${currentPath}${path.delimiter}${pandaLibPath}`;
64}
65
66export interface TextDocumentChangeInfo {
67  newDoc: string;
68  rangeStart?: number;
69  rangeEnd?: number;
70  updateText?: string;
71}
72
73export class Lsp {
74  private pandaLibPath: string;
75  private projectPath: string;
76  private fileNameToArktsconfig: Record<string, string>; // Map<fileName, arktsconfig.json>
77  private moduleToBuildConfig: Record<string, BuildConfig>; // Map<moduleName, build_config.json>
78  private getFileContent: (filePath: string) => string;
79  private filesMap: Map<string, string>; // Map<fileName, fileContent>
80
81  constructor(projectPath: string, getContentCallback?: (filePath: string) => string) {
82    initBuildEnv();
83    this.pandaLibPath = path.resolve(__dirname, '../../ets2panda/lib');
84    this.projectPath = projectPath;
85    let compileFileInfoPath = path.join(projectPath, '.idea', '.deveco', 'lsp_compileFileInfos.json');
86    this.fileNameToArktsconfig = JSON.parse(fs.readFileSync(compileFileInfoPath, 'utf-8'));
87    let buildConfigPath = path.join(projectPath, '.idea', '.deveco', 'lsp_build_config.json');
88    this.moduleToBuildConfig = JSON.parse(fs.readFileSync(buildConfigPath, 'utf-8'));
89    this.filesMap = new Map<string, string>();
90    this.getFileContent = getContentCallback || ((path: string): string => fs.readFileSync(path, 'utf8'));
91  }
92
93  modifyFilesMap(fileName: string, fileContent: TextDocumentChangeInfo): void {
94    this.filesMap.set(fileName, fileContent.newDoc);
95  }
96
97  deleteFromFilesMap(fileName: string): void {
98    this.filesMap.delete(fileName);
99  }
100
101  updateConfig(buildSdkPath: string, modules?: ModuleDescriptor[]): void {
102    generateArkTsConfigByModules(buildSdkPath, this.projectPath, modules);
103    let compileFileInfoPath = path.join(this.projectPath, '.idea', '.deveco', 'lsp_compileFileInfos.json');
104    this.fileNameToArktsconfig = JSON.parse(fs.readFileSync(compileFileInfoPath, 'utf-8'));
105    let buildConfigPath = path.join(this.projectPath, '.idea', '.deveco', 'lsp_build_config.json');
106    this.moduleToBuildConfig = JSON.parse(fs.readFileSync(buildConfigPath, 'utf-8'));
107  }
108
109  private getFileSource(filePath: string): string {
110    const getSource = this.filesMap.get(filePath) || this.getFileContent(filePath);
111    if (!getSource) {
112      throw new Error(`File content not found for path: ${filePath}`);
113    }
114    return getSource.replace(/\r\n/g, '\n');
115  }
116
117  private getModuleNameFromFilename(filePath: string): string {
118    const projectRoot = this.projectPath;
119    if (!filePath.startsWith(projectRoot)) {
120      return '';
121    }
122    const relativePath = path.relative(projectRoot, filePath);
123    const parts = relativePath.split(path.sep);
124    return parts[0] || '';
125  }
126
127  getDefinitionAtPosition(filename: String, offset: number): LspDefinitionData {
128    let lspDriverHelper = new LspDriverHelper();
129    let filePath = path.resolve(filename.valueOf());
130    let arktsconfig = this.fileNameToArktsconfig[filePath];
131    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
132    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
133    const source = this.getFileSource(filePath);
134    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
135    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
136    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
137    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
138    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
139    let ptr = global.es2panda._getDefinitionAtPosition(localCtx, offset);
140    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
141    lspDriverHelper.destroyContext(localCtx);
142    lspDriverHelper.destroyConfig(localCfg);
143    return new LspDefinitionData(ptr);
144  }
145
146  getSemanticDiagnostics(filename: String): LspDiagsNode {
147    let lspDriverHelper = new LspDriverHelper();
148    let filePath = path.resolve(filename.valueOf());
149    let arktsconfig = this.fileNameToArktsconfig[filePath];
150    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
151    let pandaLibPath: string = path.resolve(__dirname, '../../ets2panda/lib');
152    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, pandaLibPath);
153    const source = this.getFileSource(filePath);
154    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
155    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
156    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
157    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
158    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
159    let ptr = global.es2panda._getSemanticDiagnostics(localCtx);
160    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
161    lspDriverHelper.destroyContext(localCtx);
162    lspDriverHelper.destroyConfig(localCfg);
163    return new LspDiagsNode(ptr);
164  }
165
166  getCurrentTokenValue(filename: String, offset: number): string {
167    let lspDriverHelper = new LspDriverHelper();
168    let filePath = path.resolve(filename.valueOf());
169    let arktsconfig = this.fileNameToArktsconfig[filePath];
170    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
171    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
172    const source = this.getFileSource(filePath);
173    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
174    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
175    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
176    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
177    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
178    let ptr = global.es2panda._getCurrentTokenValue(localCtx, offset);
179    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
180    lspDriverHelper.destroyContext(localCtx);
181    lspDriverHelper.destroyConfig(localCfg);
182    return unpackString(ptr);
183  }
184
185  getImplementationAtPosition(filename: String, offset: number): LspDefinitionData {
186    let lspDriverHelper = new LspDriverHelper();
187    let filePath = path.resolve(filename.valueOf());
188    let arktsconfig = this.fileNameToArktsconfig[filePath];
189    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
190    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
191    const source = this.getFileSource(filePath);
192    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
193    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
194    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
195    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
196    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
197    let ptr = global.es2panda._getImplementationAtPosition(localCtx, offset);
198    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
199    lspDriverHelper.destroyContext(localCtx);
200    lspDriverHelper.destroyConfig(localCfg);
201    return new LspDefinitionData(ptr);
202  }
203
204  getFileReferences(filename: String): LspReferenceData[] {
205    let lspDriverHelper = new LspDriverHelper();
206    let searchFilePath = path.resolve(filename.valueOf());
207    let arktsconfig = this.fileNameToArktsconfig[searchFilePath];
208    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
209    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, searchFilePath, this.pandaLibPath);
210    const source = this.getFileSource(searchFilePath);
211    let localCtx = lspDriverHelper.createCtx(source, searchFilePath, localCfg);
212    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
213    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
214    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
215    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
216    let isPackageModule = global.es2panda._isPackageModule(localCtx);
217    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
218    lspDriverHelper.destroyContext(localCtx);
219    lspDriverHelper.destroyConfig(localCfg);
220    let result: LspReferenceData[] = [];
221    let moduleName = path.basename(path.dirname(arktsconfig));
222    let buildConfig: BuildConfig = this.moduleToBuildConfig[moduleName];
223    for (let i = 0; i < buildConfig.compileFiles.length; i++) {
224      let filePath = path.resolve(buildConfig.compileFiles[i]);
225      let arktsconfig = this.fileNameToArktsconfig[filePath];
226      let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
227      let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
228      const source = this.getFileSource(filePath);
229      let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
230      PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
231      lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
232      PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
233      lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
234      let ptr = global.es2panda._getFileReferences(searchFilePath, localCtx, isPackageModule);
235      let refs = new LspReferences(ptr);
236      PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
237      lspDriverHelper.destroyContext(localCtx);
238      lspDriverHelper.destroyConfig(localCfg);
239      for (let j = 0; j < refs.referenceInfos.length; j++) {
240        if (refs.referenceInfos[j].fileName !== '') {
241          result.push(refs.referenceInfos[j]);
242        }
243      }
244    }
245    return result;
246  }
247
248  getReferencesAtPosition(filename: String, offset: number): LspReferenceData[] {
249    let lspDriverHelper = new LspDriverHelper();
250    let searchFilePath = path.resolve(filename.valueOf());
251    let arktsconfig = this.fileNameToArktsconfig[searchFilePath];
252    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
253    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, searchFilePath, this.pandaLibPath);
254    const source = this.getFileSource(searchFilePath);
255    let localCtx = lspDriverHelper.createCtx(source, searchFilePath, localCfg);
256    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
257    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
258    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
259    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
260    let declInfo = global.es2panda._getDeclInfo(localCtx, offset);
261    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
262    lspDriverHelper.destroyContext(localCtx);
263    lspDriverHelper.destroyConfig(localCfg);
264    let result: LspReferenceData[] = [];
265    let moduleName = path.basename(path.dirname(arktsconfig));
266    let buildConfig: BuildConfig = this.moduleToBuildConfig[moduleName];
267    for (let i = 0; i < buildConfig.compileFiles.length; i++) {
268      let filePath = path.resolve(buildConfig.compileFiles[i]);
269      let arktsconfig = this.fileNameToArktsconfig[filePath];
270      let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
271      let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
272      const source = this.getFileSource(filePath);
273      let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
274      PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
275      lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
276      PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
277      lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
278      let ptr = global.es2panda._getReferencesAtPosition(localCtx, declInfo);
279      PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
280      lspDriverHelper.destroyContext(localCtx);
281      lspDriverHelper.destroyConfig(localCfg);
282      let refs = new LspReferences(ptr);
283      result.push(...refs.referenceInfos);
284    }
285    return Array.from(new Set(result));
286  }
287
288  getTypeHierarchies(filename: String, offset: number): LspTypeHierarchiesInfo | null {
289    let lspDriverHelper = new LspDriverHelper();
290    let filePath = path.resolve(filename.valueOf());
291    let arktsconfig = this.fileNameToArktsconfig[filePath];
292    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
293    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
294    const source = this.getFileSource(filePath);
295    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
296    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
297    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
298    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
299    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
300    let ptr = global.es2panda._getTypeHierarchies(localCtx, localCtx, offset);
301    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
302    let ref = new LspTypeHierarchiesInfo(ptr);
303    if (ref.fileName === '') {
304      lspDriverHelper.destroyContext(localCtx);
305      lspDriverHelper.destroyConfig(localCfg);
306      return null;
307    }
308    let result: LspTypeHierarchiesInfo[] = [];
309    let moduleName = path.basename(path.dirname(arktsconfig));
310    let buildConfig: BuildConfig = this.moduleToBuildConfig[moduleName];
311    for (let i = 0; i < buildConfig.compileFiles.length; i++) {
312      let filePath = path.resolve(buildConfig.compileFiles[i]);
313      let arktsconfig = this.fileNameToArktsconfig[filePath];
314      let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
315      let searchCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
316      const source = this.getFileSource(filePath);
317      let searchCtx = lspDriverHelper.createCtx(source, filePath, searchCfg);
318      PluginDriver.getInstance().getPluginContext().setContextPtr(searchCtx);
319      lspDriverHelper.proceedToState(searchCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
320      PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
321      lspDriverHelper.proceedToState(searchCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
322      let ptr = global.es2panda._getTypeHierarchies(searchCtx, localCtx, offset);
323      PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
324      lspDriverHelper.destroyContext(searchCtx);
325      lspDriverHelper.destroyConfig(searchCfg);
326      let refs = new LspTypeHierarchiesInfo(ptr);
327      if (i > 0) {
328        result[0].subHierarchies.subOrSuper = result[0].subHierarchies.subOrSuper.concat(refs.subHierarchies.subOrSuper);
329      } else {
330        result.push(refs);
331      }
332    }
333    for (let j = 0; j < result[0].subHierarchies.subOrSuper.length; j++) {
334      let res = this.getTypeHierarchies(result[0].subHierarchies.subOrSuper[j].fileName, result[0].subHierarchies.subOrSuper[j].pos);
335      if (res !== null) {
336        let subOrSuperTmp = result[0].subHierarchies.subOrSuper[j].subOrSuper.concat(res.subHierarchies.subOrSuper);
337        result[0].subHierarchies.subOrSuper[j].subOrSuper = Array.from(
338          new Map(subOrSuperTmp.map(item => [`${item.fileName}-${item.type}-${item.pos}-${item.name}`, item])).values()
339        );
340      }
341    }
342    return result[0];
343  }
344
345  getClassHierarchyInfo(filename: String, offset: number): LspClassHierarchy {
346    let lspDriverHelper = new LspDriverHelper();
347    let filePath = path.resolve(filename.valueOf());
348    let arktsconfig = this.fileNameToArktsconfig[filePath];
349    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
350    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
351    const source = this.getFileContent(filePath).replace(/\r\n/g, '\n');
352    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
353    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
354    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
355    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
356    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
357    let ptr = global.es2panda._getClassHierarchyInfo(localCtx, offset);
358    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
359    lspDriverHelper.destroyContext(localCtx);
360    lspDriverHelper.destroyConfig(localCfg);
361    return new LspClassHierarchy(ptr);
362  }
363
364  getAliasScriptElementKind(filename: String, offset: number): LspCompletionEntryKind {
365    let lspDriverHelper = new LspDriverHelper();
366    let filePath = path.resolve(filename.valueOf());
367    let arktsconfig = this.fileNameToArktsconfig[filePath];
368    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
369    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
370    const source = this.getFileContent(filePath).replace(/\r\n/g, '\n');
371    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
372    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
373    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
374    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
375    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
376    let kind = global.es2panda._getAliasScriptElementKind(localCtx, offset);
377    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
378    lspDriverHelper.destroyContext(localCtx);
379    lspDriverHelper.destroyConfig(localCfg);
380    return kind;
381  }
382
383  getClassHierarchies(filename: String, offset: number): LspClassHierarchies {
384    let lspDriverHelper = new LspDriverHelper();
385    let filePath = path.resolve(filename.valueOf());
386    let arktsconfig = this.fileNameToArktsconfig[filePath];
387    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
388    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
389    const source = this.getFileContent(filePath).replace(/\r\n/g, '\n');
390    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
391    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
392    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
393    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
394    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
395    let ptr = global.es2panda._getClassHierarchies(localCtx, filename, offset);
396    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
397    lspDriverHelper.destroyContext(localCtx);
398    lspDriverHelper.destroyConfig(localCfg);
399    return new LspClassHierarchies(ptr);
400  }
401
402  getClassPropertyInfo(filename: String, offset: number, shouldCollectInherited: boolean = false): LspClassPropertyInfo {
403    let lspDriverHelper = new LspDriverHelper();
404    let filePath = path.resolve(filename.valueOf());
405    let arktsconfig = this.fileNameToArktsconfig[filePath];
406    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
407    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
408    const source = this.getFileContent(filePath).replace(/\r\n/g, '\n');
409    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
410    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
411    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
412    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
413    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
414    let ptr = global.es2panda._getClassPropertyInfo(localCtx, offset, shouldCollectInherited);
415    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
416    lspDriverHelper.destroyContext(localCtx);
417    lspDriverHelper.destroyConfig(localCfg);
418    return new LspClassPropertyInfo(ptr);
419  }
420
421  getOrganizeImports(filename: String): LspFileTextChanges {
422    let lspDriverHelper = new LspDriverHelper();
423    let filePath = path.resolve(filename.valueOf());
424    let arktsconfig = this.fileNameToArktsconfig[filePath];
425    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
426    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
427    const source = this.getFileSource(filePath);
428    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
429    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
430    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
431    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
432    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
433    let ptr = global.es2panda._organizeImports(localCtx, filename);
434    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
435    lspDriverHelper.destroyContext(localCtx);
436    lspDriverHelper.destroyConfig(localCfg);
437    return new LspFileTextChanges(ptr);
438  }
439
440  findSafeDeleteLocation(filename: String, offset: number): LspSafeDeleteLocationInfo[] {
441    let lspDriverHelper = new LspDriverHelper();
442    let filePath = path.resolve(filename.valueOf());
443    let arktsconfig = this.fileNameToArktsconfig[filePath];
444    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
445    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
446    const source = this.getFileSource(filePath);
447    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
448    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
449    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
450    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
451    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
452    let declInfo = global.es2panda._getDeclInfo(localCtx, offset);
453    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
454    lspDriverHelper.destroyContext(localCtx);
455    lspDriverHelper.destroyConfig(localCfg);
456    let result: LspSafeDeleteLocationInfo[] = [];
457    let moduleName = path.basename(path.dirname(arktsconfig));
458    let buildConfig: BuildConfig = this.moduleToBuildConfig[moduleName];
459    for (let i = 0; i < buildConfig.compileFiles.length; i++) {
460      let filePath = path.resolve(buildConfig.compileFiles[i]);
461      let arktsconfig = this.fileNameToArktsconfig[filePath];
462      let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
463      let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
464      const source = this.getFileSource(filePath);
465      let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
466      PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
467      lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
468      PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
469      lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
470      let ptr = global.es2panda._findSafeDeleteLocation(localCtx, declInfo);
471      PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
472      lspDriverHelper.destroyContext(localCtx);
473      lspDriverHelper.destroyConfig(localCfg);
474      let refs = new LspSafeDeleteLocation(ptr);
475      result.push(...refs.safeDeleteLocationInfos);
476    }
477    return Array.from(new Set(result));
478  }
479
480  getCompletionEntryDetails(filename: String, offset: number, entryName: String): CompletionEntryDetails {
481    let lspDriverHelper = new LspDriverHelper();
482    let filePath = path.resolve(filename.valueOf());
483    let arktsconfig = this.fileNameToArktsconfig[filePath];
484    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
485    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
486    const source = this.getFileSource(filePath);
487    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
488    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
489    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
490    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
491    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
492    let ptr = global.es2panda._getCompletionEntryDetails(entryName, filename, localCtx, offset);
493    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
494    lspDriverHelper.destroyContext(localCtx);
495    lspDriverHelper.destroyConfig(localCfg);
496    return new CompletionEntryDetails(ptr);
497  }
498
499  getApplicableRefactors(filename: String, kind: String, offset: number): ApplicableRefactorItemInfo[] {
500    let lspDriverHelper = new LspDriverHelper();
501    let filePath = path.resolve(filename.valueOf());
502    let arktsconfig = this.fileNameToArktsconfig[filePath];
503    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
504    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
505    const source = this.getFileSource(filePath);
506    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
507    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
508    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
509    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
510    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
511    let result: ApplicableRefactorItemInfo[] = [];
512    let ptr = global.es2panda._getApplicableRefactors(localCtx, kind, offset);
513    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
514    lspDriverHelper.destroyContext(localCtx);
515    lspDriverHelper.destroyConfig(localCfg);
516    let refs = new LspApplicableRefactorInfo(ptr);
517    result.push(...refs.applicableRefactorInfo);
518    return Array.from(new Set(result));
519  }
520
521  getClassConstructorInfo(filename: String, offset: number, properties: string[]): LspClassConstructorInfo {
522    let lspDriverHelper = new LspDriverHelper();
523    let filePath = path.resolve(filename.valueOf());
524    let arktsconfig = this.fileNameToArktsconfig[filePath];
525    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
526    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
527    const source = this.getFileSource(filePath);
528    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
529    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
530    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
531    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
532    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
533    let ptr = global.es2panda._getClassConstructorInfo(localCtx, offset, passStringArray(properties));
534    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
535    lspDriverHelper.destroyContext(localCtx);
536    lspDriverHelper.destroyConfig(localCfg);
537    return new LspClassConstructorInfo(ptr);
538  }
539
540  getSyntacticDiagnostics(filename: String): LspDiagsNode {
541    let lspDriverHelper = new LspDriverHelper();
542    let filePath = path.resolve(filename.valueOf());
543    let arktsconfig = this.fileNameToArktsconfig[filePath];
544    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
545    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
546    const source = this.getFileSource(filePath);
547    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
548    const moduleName = this.getModuleNameFromFilename(filePath);
549    const buildConfig = this.moduleToBuildConfig[moduleName];
550    PluginDriver.getInstance().getPluginContext().setProjectConfig(buildConfig);
551    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
552    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
553    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
554    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
555    let ptr = global.es2panda._getSyntacticDiagnostics(localCtx);
556    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
557    lspDriverHelper.destroyContext(localCtx);
558    lspDriverHelper.destroyConfig(localCfg);
559    return new LspDiagsNode(ptr);
560  }
561
562  getSuggestionDiagnostics(filename: String): LspDiagsNode {
563    let lspDriverHelper = new LspDriverHelper();
564    let filePath = path.resolve(filename.valueOf());
565    let arktsconfig = this.fileNameToArktsconfig[filePath];
566    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
567    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
568    const source = this.getFileSource(filePath);
569    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
570    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
571    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
572    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
573    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
574    let ptr = global.es2panda._getSuggestionDiagnostics(localCtx);
575    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
576    lspDriverHelper.destroyContext(localCtx);
577    lspDriverHelper.destroyConfig(localCfg);
578    return new LspDiagsNode(ptr);
579  }
580
581  getQuickInfoAtPosition(filename: String, offset: number): LspQuickInfo {
582    let lspDriverHelper = new LspDriverHelper();
583    let filePath = path.resolve(filename.valueOf());
584    let arktsconfig = this.fileNameToArktsconfig[filePath];
585    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
586    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
587    const source = this.getFileSource(filePath);
588    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
589    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
590    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
591    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
592    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
593    let ptr = global.es2panda._getQuickInfoAtPosition(filename, localCtx, offset);
594    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
595    lspDriverHelper.destroyContext(localCtx);
596    lspDriverHelper.destroyConfig(localCfg);
597    return new LspQuickInfo(ptr);
598  }
599
600  getDocumentHighlights(filename: String, offset: number): LspDocumentHighlightsReferences {
601    let lspDriverHelper = new LspDriverHelper();
602    let filePath = path.resolve(filename.valueOf());
603    let arktsconfig = this.fileNameToArktsconfig[filePath];
604    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
605    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
606    const source = this.getFileSource(filePath);
607    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
608    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
609    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
610    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
611    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
612    let ptr = global.es2panda._getDocumentHighlights(localCtx, offset);
613    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
614    lspDriverHelper.destroyContext(localCtx);
615    lspDriverHelper.destroyConfig(localCfg);
616    return new LspDocumentHighlightsReferences(ptr);
617  }
618
619  getCompletionAtPosition(filename: String, offset: number): LspCompletionInfo {
620    let lspDriverHelper = new LspDriverHelper();
621    let filePath = path.resolve(filename.valueOf());
622    let arktsconfig = this.fileNameToArktsconfig[filePath];
623    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
624    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
625    let source = this.getFileSource(filePath);
626    // This is a temporary solution to support "obj." with wildcard for better solution in internal issue.
627    if (source[offset - 1] === '.') {
628      const wildcard = '_WILDCARD';
629      if (offset < source.length + 1) {
630        source = source.slice(0, offset) + wildcard + source.slice(offset);
631      } else {
632        source += wildcard;
633      }
634      offset += wildcard.length;
635    }
636    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
637    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
638    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
639    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
640    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
641    let ptr = global.es2panda._getCompletionAtPosition(localCtx, offset);
642    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
643    lspDriverHelper.destroyContext(localCtx);
644    lspDriverHelper.destroyConfig(localCfg);
645    return new LspCompletionInfo(ptr);
646  }
647
648  toLineColumnOffset(filename: String, offset: number): LspLineAndCharacter {
649    let lspDriverHelper = new LspDriverHelper();
650    let filePath = path.resolve(filename.valueOf());
651    let arktsconfig = this.fileNameToArktsconfig[filePath];
652    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
653    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
654    const source = this.getFileSource(filePath);
655    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
656    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
657    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
658    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
659    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
660    let ptr = global.es2panda._toLineColumnOffset(localCtx, offset);
661    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
662    lspDriverHelper.destroyContext(localCtx);
663    lspDriverHelper.destroyConfig(localCfg);
664    return new LspLineAndCharacter(ptr);
665  }
666
667  getSafeDeleteInfo(filename: String, position: number): boolean {
668    let lspDriverHelper = new LspDriverHelper();
669    let filePath = path.resolve(filename.valueOf());
670    let arktsconfig = this.fileNameToArktsconfig[filePath];
671    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
672    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
673    const source = this.getFileSource(filePath);
674    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
675    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
676    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
677    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
678    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
679    let result = global.es2panda._getSafeDeleteInfo(localCtx, position);
680    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
681    lspDriverHelper.destroyContext(localCtx);
682    lspDriverHelper.destroyConfig(localCfg);
683    return result;
684  }
685
686  getSpanOfEnclosingComment(filename: String, offset: number, onlyMultiLine: boolean): LspTextSpan {
687    let lspDriverHelper = new LspDriverHelper();
688    let filePath = path.resolve(filename.valueOf());
689    let arktsconfig = this.fileNameToArktsconfig[filePath];
690    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
691    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
692    const source = this.getFileSource(filePath);
693    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
694    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
695    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
696    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
697    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
698    let ptr = global.es2panda._getSpanOfEnclosingComment(localCtx, offset, onlyMultiLine);
699    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
700    lspDriverHelper.destroyContext(localCtx);
701    lspDriverHelper.destroyConfig(localCfg);
702    return new LspTextSpan(ptr);
703  }
704
705  getCodeFixesAtPosition(filename: String, start: number, end: number, errorCodes: number[]): CodeFixActionInfo[] {
706    let lspDriverHelper = new LspDriverHelper();
707    let filePath = path.resolve(filename.valueOf());
708    let arktsconfig = this.fileNameToArktsconfig[filePath];
709    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
710    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
711    const source = this.getFileSource(filePath);
712    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
713    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
714    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
715    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
716    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
717    let ptr = global.es2panda._getCodeFixesAtPosition(localCtx, start, end, new Int32Array(errorCodes), errorCodes.length);
718    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
719    lspDriverHelper.destroyContext(localCtx);
720    lspDriverHelper.destroyConfig(localCfg);
721    const codeFixActionInfoList = new CodeFixActionInfoList(ptr);
722    const codeFixActionInfos: CodeFixActionInfo[] = [];
723    codeFixActionInfos.push(...codeFixActionInfoList.codeFixActionInfos);
724    return codeFixActionInfos;
725  }
726
727  provideInlayHints(filename: String, span: TextSpan): LspInlayHint[] {
728    let lspDriverHelper = new LspDriverHelper();
729    let filePath = path.resolve(filename.valueOf());
730    let arktsconfig = this.fileNameToArktsconfig[filePath];
731    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
732    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
733    const source = this.getFileSource(filePath);
734    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
735    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
736    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
737    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
738    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
739    const nativeSpan = global.es2panda._createTextSpan(span.start, span.length);
740    let ptr = global.es2panda._getInlayHintList(localCtx, nativeSpan);
741    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
742    lspDriverHelper.destroyContext(localCtx);
743    lspDriverHelper.destroyConfig(localCfg);
744    const inlayHintList = new LspInlayHintList(ptr);
745    const inlayHints: LspInlayHint[] = [];
746    inlayHints.push(...inlayHintList.inlayHints);
747    return inlayHints;
748  }
749
750  getSignatureHelpItems(filename: String, offset: number): LspSignatureHelpItems {
751    let lspDriverHelper = new LspDriverHelper();
752    let filePath = path.resolve(filename.valueOf());
753    let arktsconfig = this.fileNameToArktsconfig[filePath];
754    let ets2pandaCmd = ets2pandaCmdPrefix.concat(arktsconfig);
755    let localCfg = lspDriverHelper.createCfg(ets2pandaCmd, filePath, this.pandaLibPath);
756    const source = this.getFileSource(filePath);
757    let localCtx = lspDriverHelper.createCtx(source, filePath, localCfg);
758    PluginDriver.getInstance().getPluginContext().setContextPtr(localCtx);
759    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED);
760    PluginDriver.getInstance().runPluginHook(PluginHook.PARSED);
761    lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED);
762    let ptr = global.es2panda._getSignatureHelpItems(localCtx, offset);
763    PluginDriver.getInstance().runPluginHook(PluginHook.CLEAN);
764    lspDriverHelper.destroyContext(localCtx);
765    lspDriverHelper.destroyConfig(localCfg);
766    return new LspSignatureHelpItems(ptr);
767  }
768}
769