Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LS integration for diagnostics & resource-reference #1150

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

nighca
Copy link
Collaborator

@nighca nighca commented Dec 17, 2024

close #1149.

Copy link

qiniu-prow bot commented Dec 17, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 13 out of 28 changed files in this pull request and generated no comments.

Files not reviewed (15)
  • spx-gui/src/components/editor/code-editor/ui/diagnostics/DiagnosticsUI.vue: Evaluated as low risk
  • spx-gui/src/components/editor/code-editor/ui/resource/ResourceItem.vue: Evaluated as low risk
  • spx-gui/src/components/editor/code-editor/ui/resource-reference/selector/ResourceSelector.vue: Evaluated as low risk
  • spx-gui/src/components/editor/code-editor/ui/resource-reference/ResourceReferenceUI.vue: Evaluated as low risk
  • spx-gui/src/components/editor/code-editor/ui/markdown/ResourcePreview.vue: Evaluated as low risk
  • spx-gui/src/components/editor/code-editor/ui/CodeEditorUI.vue: Evaluated as low risk
  • spx-gui/src/components/editor/code-editor/ui/markdown/MarkdownView.vue: Evaluated as low risk
  • spx-gui/src/components/editor/code-editor/CodeEditor.vue: Evaluated as low risk
  • spx-gui/src/components/editor/code-editor/ui/markdown/DiagnosticItem.vue: Evaluated as low risk
  • spx-gui/src/components/editor/code-editor/lsp/index.ts: Evaluated as low risk
  • spx-gui/src/components/editor/code-editor/ui/common.ts: Evaluated as low risk
  • spx-gui/src/components/editor/code-editor/ui/completion/index.ts: Evaluated as low risk
  • spx-gui/src/components/editor/code-editor/ui/index.ts: Evaluated as low risk
  • spx-gui/src/components/editor/code-editor/ui/hover/index.ts: Evaluated as low risk
  • spx-gui/src/components/editor/code-editor/ui/resource-reference/index.ts: Evaluated as low risk
Comments suppressed due to low confidence (4)

spx-gui/src/components/editor/code-editor/common.ts:451

  • [nitpick] The function name positionEq should be renamed to arePositionsEqual for clarity.
export function positionEq(a: Position | null, b: Position | null) {

spx-gui/src/components/editor/code-editor/ui/resource-reference/selector/index.ts:198

  • [nitpick] The variable name 'parsed' is used multiple times within the same function. Consider using more descriptive names for each instance.
const parsed = parseResourceURI(rr.resource.uri)

spx-gui/src/components/editor/code-editor/ui/resource-reference/selector/index.ts:213

  • [nitpick] The error message 'Unexpected sub-resource type: ${parsed[1].type}' could be more descriptive to provide more context about why the sub-resource type is unexpected.
throw new Error(`Unexpected sub-resource type: ${parsed[1].type}`)

spx-gui/src/components/editor/code-editor/ui/resource-reference/selector/index.ts:221

  • [nitpick] The error message 'Unexpected resource type: ${parsed[0].type}' could be more descriptive to provide more context about why the resource type is unexpected.
throw new Error(`Unexpected resource type: ${parsed[0].type}`)
@@ -90,7 +90,10 @@ func (r *compileResult) innermostScopeAt(pos goptoken.Pos) *types.Scope {
// The `MainEntry` scope is the last child of the main package and covers all positions in the workspace.
// We need to skip `MainEntry` when searching for the innermost scope, as the file scope will be more precise.
// Especially for positions in trailing empty lines of a file, the file scope does not contain them in its position range.
mainEntryScope := mainPkgScope.Child(mainPkgScope.Len() - 1)
var mainEntryScope *types.Scope
if mainPkgScope.Len() > 0 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是遇到过 mainPkgScope 一个 child 也没有的情况,所以处理下

现在感觉直接认最后一个 child 就是 MainEntry 也未必准确,不过暂时没有想到更好的识别方式,就先没动

@@ -10,7 +10,7 @@ func (s *Server) textDocumentDiagnostic(params *DocumentDiagnosticParams) (*Docu
return &DocumentDiagnosticReport{Value: &RelatedFullDocumentDiagnosticReport{
FullDocumentDiagnosticReport: FullDocumentDiagnosticReport{
Kind: string(DiagnosticFull),
Items: result.diagnostics[params.TextDocument.URI],
Items: append([]Diagnostic{}, result.diagnostics[params.TextDocument.URI]...),
Copy link
Collaborator Author

@nighca nighca Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确保 items 为空时 JSON 序列化后是 [] 而不是 null,跟 LSP 这里的要求保持一致

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果这是 LSP 要求的,那感觉在

result.diagnostics[documentURI] = nil
这里改成初始化空数组可能更合适些

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,LSP 中 items 的类型是 Diagnostic[];我来调整下

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return [
ResourceReferenceKind.AutoBindingReference,
// ResourceReferenceKind.AutoBindingReference, // consider cases like `Foo.say "xxx"`, modifying `Foo` is complicated
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

情况比我预计的复杂,暂时先不支持 AutoBindingReference 的 modify..

async textDocumentDiagnostic(params: lsp.DocumentDiagnosticParams): Promise<lsp.DocumentDiagnosticReport> {
const spxlc = await this.prepareRquest()
const report = await spxlc.request<any>(lsp.DocumentDiagnosticRequest.method, params)
return report.value // TODO: this should be fixed in `spxls`, see type `DocumentDiagnosticReport` there for more details
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里需要瞅一眼,我没想好 ls 那里怎么改合适,所以先没改那里

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

指的是返回的结果不应该是:

{
    "value": {
        "kind": "full",
        "items": []
    }
}

而应该是:

{
    "kind": "full",
    "items": []
}

是这个意思吗?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对的,不应该有 value 这一层

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hhh 要不这个你来处理吧?你改完之后帮我把这边改成

return spxlc.request<lsp.DocumentDiagnosticReport>(lsp.DocumentDiagnosticRequest.method, params)

就好

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯可以的,那先合吧

}
private adaptDiagnosticRange({ start, end }: Range, textDocument: ITextDocument) {
// make sure the range is not empty, so that the diagnostic info can be displayed as inline decorations
// TODO: it's a workaround, should be fixed in the server side
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

对于空 range 的 diagnostic,先处理成向后或向前找到第一个非换行字符,使用这个字符作为 range,这样确保至少有一个字符会被高亮(波浪线 & hover)

@nighca nighca marked this pull request as ready for review December 18, 2024 02:40
Copy link

qiniu-prow bot commented Dec 18, 2024

@nighca: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
goplus-builder-pr-review-environment-test 57de383 link true /test goplus-builder-pr-review-environment-test

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@aofei aofei merged commit fb662b5 into goplus:dev Dec 19, 2024
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Language server integration in code editor - Resource Reference & Diagnostics
2 participants