From f302796d06046dae2818723e1f9f53ed86e2c831 Mon Sep 17 00:00:00 2001 From: liushitong Date: Mon, 4 Aug 2025 11:17:50 +0800 Subject: [PATCH] [LSP]: fix getSyntacticDiagnostics Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICQT88 Signed-off-by: liushitong Change-Id: Ia4d2ff5d78e62f200af8c1147375a8d4c5e58d4e --- ets2panda/bindings/src/lsp/lsp_helper.ts | 8 +- ets2panda/bindings/test/cases.ts | 3 +- .../expected/getSyntacticDiagnostics.json | 115 +++++++++++++++++- .../getSyntacticDiagnostics4.ets | 46 +++++++ 4 files changed, 165 insertions(+), 7 deletions(-) create mode 100644 ets2panda/bindings/test/testcases/getSyntacticDiagnostics/getSyntacticDiagnostics4.ets diff --git a/ets2panda/bindings/src/lsp/lsp_helper.ts b/ets2panda/bindings/src/lsp/lsp_helper.ts index f73d2cd589..e2de0c6018 100644 --- a/ets2panda/bindings/src/lsp/lsp_helper.ts +++ b/ets2panda/bindings/src/lsp/lsp_helper.ts @@ -159,7 +159,7 @@ export class Lsp { return getSource.replace(/\r\n/g, '\n'); } - private createContext(filename: String): [Config, KNativePointer] { + private createContext(filename: String, processToCheck: boolean = true): [Config, KNativePointer] { const filePath = path.resolve(filename.valueOf()); const arktsconfig = this.moduleInfos[filePath]?.arktsConfigFile; if (!arktsconfig) { @@ -182,7 +182,9 @@ export class Lsp { this.lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_PARSED); PluginDriver.getInstance().runPluginHook(PluginHook.PARSED); - this.lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED); + if (processToCheck) { + this.lspDriverHelper.proceedToState(localCtx, Es2pandaContextState.ES2PANDA_STATE_CHECKED); + } return [localCfg, localCtx]; } catch (error) { this.lspDriverHelper.destroyContext(localCtx); @@ -549,7 +551,7 @@ export class Lsp { getSyntacticDiagnostics(filename: String): LspDiagsNode { let ptr: KPointer; - const [cfg, ctx] = this.createContext(filename); + const [cfg, ctx] = this.createContext(filename, false); try { ptr = global.es2panda._getSyntacticDiagnostics(ctx); } finally { diff --git a/ets2panda/bindings/test/cases.ts b/ets2panda/bindings/test/cases.ts index 583e8a93d3..9afdb36a79 100644 --- a/ets2panda/bindings/test/cases.ts +++ b/ets2panda/bindings/test/cases.ts @@ -97,7 +97,8 @@ export const basicCases: TestCases = { expectedFilePath: resolveTestPath('test/expected/getSyntacticDiagnostics.json'), '1': [resolveTestPath('test/testcases/getSyntacticDiagnostics/getSyntacticDiagnostics1.ets')], '2': [resolveTestPath('test/testcases/getSyntacticDiagnostics/getSyntacticDiagnostics2.ets')], - '3': [resolveTestPath('test/testcases/getSyntacticDiagnostics/getSyntacticDiagnostics3.ets')] + '3': [resolveTestPath('test/testcases/getSyntacticDiagnostics/getSyntacticDiagnostics3.ets')], + '4': [resolveTestPath('test/testcases/getSyntacticDiagnostics/getSyntacticDiagnostics4.ets')] }, getSuggestionDiagnostics: { expectedFilePath: resolveTestPath('test/expected/getSuggestionDiagnostics.json'), diff --git a/ets2panda/bindings/test/expected/getSyntacticDiagnostics.json b/ets2panda/bindings/test/expected/getSyntacticDiagnostics.json index 2abdaa1016..e51e4621f7 100644 --- a/ets2panda/bindings/test/expected/getSyntacticDiagnostics.json +++ b/ets2panda/bindings/test/expected/getSyntacticDiagnostics.json @@ -156,11 +156,11 @@ "range": { "start": { "line": 16, - "character": 1 + "character": 24 }, "end": { - "line": 20, - "character": 20 + "line": 16, + "character": 24 } }, "tags": [], @@ -303,5 +303,114 @@ } } ] + }, + "4": { + "diagnostics": [ + { + "message": "A function can only be decorated by the 'Builder'.", + "range": { + "start": { + "line": 22, + "character": 2 + }, + "end": { + "line": 22, + "character": 7 + } + }, + "tags": [], + "relatedInfo": [], + "code": 4000, + "data": 0, + "severity": 1, + "codeDescription": { + "href": "test code description" + } + }, + { + "message": "The '@Track' annotation can decorate only member variables of a class.", + "range": { + "start": { + "line": 19, + "character": 2 + }, + "end": { + "line": 19, + "character": 7 + } + }, + "tags": [], + "relatedInfo": [], + "code": 4000, + "data": 0, + "severity": 1, + "codeDescription": { + "href": "test code description" + } + }, + { + "message": "The '@Track' annotation can decorate only member variables of a class.", + "range": { + "start": { + "line": 22, + "character": 2 + }, + "end": { + "line": 22, + "character": 7 + } + }, + "tags": [], + "relatedInfo": [], + "code": 4000, + "data": 0, + "severity": 1, + "codeDescription": { + "href": "test code description" + } + }, + { + "message": "The '@Track' annotation can decorate only member variables of a class.", + "range": { + "start": { + "line": 27, + "character": 2 + }, + "end": { + "line": 27, + "character": 7 + } + }, + "tags": [], + "relatedInfo": [], + "code": 4000, + "data": 0, + "severity": 1, + "codeDescription": { + "href": "test code description" + } + }, + { + "message": "The '@Track' annotation can decorate only member variables of a class.", + "range": { + "start": { + "line": 36, + "character": 6 + }, + "end": { + "line": 36, + "character": 11 + } + }, + "tags": [], + "relatedInfo": [], + "code": 4000, + "data": 0, + "severity": 1, + "codeDescription": { + "href": "test code description" + } + } + ] } } diff --git a/ets2panda/bindings/test/testcases/getSyntacticDiagnostics/getSyntacticDiagnostics4.ets b/ets2panda/bindings/test/testcases/getSyntacticDiagnostics/getSyntacticDiagnostics4.ets new file mode 100644 index 0000000000..e40cd7d11b --- /dev/null +++ b/ets2panda/bindings/test/testcases/getSyntacticDiagnostics/getSyntacticDiagnostics4.ets @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { Entry, Component, Row, Column, Text } from '@ohos.arkui.component'; +import { Track } from '@ohos.arkui.stateManagement'; + +@Track +let A: number = 0; + +@Track +function B() { + +} + +@Track +interface IUser { + name: string; + age: number; +} + +@Entry +@Component +struct Index { + @Track + funA() { + + } + + build() { + Row() { + Text('Hello World') + } + } +} \ No newline at end of file -- Gitee