Skip to content

Commit 6edad16

Browse files
authored
Fix interactive window diagnostics position (#16838)
* Fix interactive window diagnostics position. * resolve review.
1 parent e7fa226 commit 6edad16

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/client/jupyter/languageserver/interactiveConcatTextDocument.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class InteractiveConcatTextDocument implements IConcatTextDocument {
3838
}
3939

4040
get lineCount(): number {
41-
return this._lineCounts[0] + 1 + this._lineCounts[1];
41+
return this._lineCounts[0] + this._lineCounts[1];
4242
}
4343

4444
get languageId(): string {
@@ -65,9 +65,6 @@ export class InteractiveConcatTextDocument implements IConcatTextDocument {
6565
}
6666
});
6767

68-
this._updateConcat();
69-
this._updateInput();
70-
7168
const counter = /Interactive-(\d+)\.interactive/.exec(this._notebook.uri.path);
7269
if (counter) {
7370
this._input = workspace.textDocuments.find(
@@ -90,6 +87,9 @@ export class InteractiveConcatTextDocument implements IConcatTextDocument {
9087
}
9188
});
9289
}
90+
91+
this._updateConcat();
92+
this._updateInput();
9393
}
9494

9595
private _updateConcat() {
@@ -98,15 +98,12 @@ export class InteractiveConcatTextDocument implements IConcatTextDocument {
9898
for (let i = 0; i < this._notebook.cellCount; i += 1) {
9999
const cell = this._notebook.cellAt(i);
100100
if (score(cell.document, this._selector)) {
101-
concatLineCnt += cell.document.lineCount + 1;
101+
concatLineCnt += cell.document.lineCount;
102102
concatTextLen += this._getDocumentTextLen(cell.document) + 1;
103103
}
104104
}
105105

106-
this._lineCounts = [
107-
concatLineCnt > 0 ? concatLineCnt - 1 : 0, // NotebookConcatTextDocument.lineCount
108-
this._lineCounts[1],
109-
];
106+
this._lineCounts = [concatLineCnt, this._lineCounts[1]];
110107

111108
this._textLen = [concatTextLen > 0 ? concatTextLen - 1 : 0, this._textLen[1]];
112109
}
@@ -126,9 +123,12 @@ export class InteractiveConcatTextDocument implements IConcatTextDocument {
126123

127124
getText(range?: Range): string {
128125
if (!range) {
129-
let result = '';
130-
result += `${this._concatTextDocument.getText()}\n${this._input?.getText() ?? ''}`;
131-
return result;
126+
if (this._lineCounts[0] === 0) {
127+
// empty
128+
return this._input?.getText() ?? '';
129+
}
130+
131+
return `${this._concatTextDocument.getText()}\n${this._input?.getText() ?? ''}`;
132132
}
133133

134134
if (range.isEmpty) {
@@ -198,9 +198,9 @@ export class InteractiveConcatTextDocument implements IConcatTextDocument {
198198
const start = positionOrRange.start.line;
199199
if (start >= this._lineCounts[0]) {
200200
// this is the inputbox
201-
const offset = Math.max(0, start - this._lineCounts[0] - 1);
201+
const offset = start - this._lineCounts[0];
202202
const startPosition = new Position(offset, positionOrRange.start.character);
203-
const endOffset = Math.max(0, positionOrRange.end.line - this._lineCounts[0] - 1);
203+
const endOffset = positionOrRange.end.line - this._lineCounts[0];
204204
const endPosition = new Position(endOffset, positionOrRange.end.character);
205205

206206
// TODO@rebornix !
@@ -230,15 +230,15 @@ export class InteractiveConcatTextDocument implements IConcatTextDocument {
230230
lineAt(posOrNumber: Position | number): TextLine {
231231
const position = typeof posOrNumber === 'number' ? new Position(posOrNumber, 0) : posOrNumber;
232232

233+
if (position.line >= this._lineCounts[0] && this._input) {
234+
// this is the input box
235+
return this._input?.lineAt(position.line - this._lineCounts[0]);
236+
}
237+
233238
// convert this position into a cell location
234239
// (we need the translated location, that's why we can't use getCellAtPosition)
235240
const location = this._concatTextDocument.locationAt(position);
236241

237-
// Get the cell at this location
238-
if (location.uri.toString() === this._input?.uri.toString()) {
239-
return this._input.lineAt(location.range.start);
240-
}
241-
242242
const cell = this._notebook.getCells().find((c) => c.document.uri.toString() === location.uri.toString());
243243
return cell!.document.lineAt(location.range.start);
244244
}

0 commit comments

Comments
 (0)