-
Notifications
You must be signed in to change notification settings - Fork 26
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
Conversation
Skipping CI for Draft Pull Request. |
There was a problem hiding this comment.
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 toarePositionsEqual
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 { |
There was a problem hiding this comment.
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]...), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确保 items 为空时 JSON 序列化后是 []
而不是 null
,跟 LSP 这里的要求保持一致
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的,LSP 中 items 的类型是 Diagnostic[]
;我来调整下
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里需要瞅一眼,我没想好 ls 那里怎么改合适,所以先没改那里
There was a problem hiding this comment.
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": []
}
是这个意思吗?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对的,不应该有 value
这一层
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯我看到了,我从 gopls 那里拷过来的时候漏了点东西,应该把 https://github.com/golang/tools/blob/74dea82592ad27cc0a4954831ee4bca305ed5ebd/gopls/internal/protocol/tsjson.go 这个文件的内容也拷进 protocol.go 才对,这里面有对 Value
做处理:
There was a problem hiding this comment.
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)
就好
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: The following test failed, say
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. |
close #1149.