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

fix(inlayHint&semanticTokens): Fix range send to server #5192

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/handler/inlayHint/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export default class InlayHintBuffer implements SyncItem {
if (token.isCancellationRequested || this.regions.has(res[0], res[1])) return
const startLine = Math.max(0, res[0] - RenderRangeExtendSize)
const endLine = Math.min(this.doc.lineCount, res[1] + RenderRangeExtendSize)
let range = Range.create(startLine, 0, endLine, 0)
let range = this.doc.textDocument.intersectWith(Range.create(startLine, 0, endLine, 0))
let inlayHints = await this.requestInlayHints(range, token)
if (inlayHints == null || token.isCancellationRequested) return
this.regions.add(res[0], res[1])
Expand Down
2 changes: 1 addition & 1 deletion src/handler/semanticTokens/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ export default class SemanticTokensBuffer implements SyncItem {
let region = await nvim.call('coc#window#visible_range') as [number, number]
if (!region || token.isCancellationRequested) return null
let endLine = Math.min(region[0] + workspace.env.lines * 2, region[1] + workspace.env.lines, doc.lineCount)
let range = Range.create(region[0] - 1, 0, endLine, 0)
let range = doc.textDocument.intersectWith(Range.create(region[0] - 1, 0, endLine, 0))
let res = await languages.provideDocumentRangeSemanticTokens(doc.textDocument, range, token)
if (!res || !SemanticTokens.is(res) || token.isCancellationRequested) return null
let legend = languages.getLegend(doc.textDocument, true)
Expand Down
18 changes: 18 additions & 0 deletions src/model/textdocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ export class LinesTextDocument implements TextDocument {
return this.lines.length + (this.eol ? 1 : 0)
}

public intersectWith(range: Range): Range {
let start: Position = Position.create(0, 0)
if (start.line < range.start.line) {
start = range.start
} else if (range.start.line === start.line) {
start = Position.create(start.line, Math.max(start.character, range.start.character))
}

let end: Position = this.end
if (range.end.line < end.line) {
end = range.end
} else if (range.end.line === end.line) {
end = Position.create(end.line, Math.min(end.character, range.end.character))
fannheyward marked this conversation as resolved.
Show resolved Hide resolved
}

return Range.create(start, end)
}

public getText(range?: Range): string {
if (range) {
let { start, end } = range
Expand Down
Loading