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

Virtual concat document with extra lines #25

Merged
merged 18 commits into from
Nov 19, 2021
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
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vscode/jupyter-lsp-middleware",
"version": "0.2.23",
"version": "0.2.24",
"description": "VS Code Python Language Server Middleware for Jupyter Notebook",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand All @@ -19,6 +19,7 @@
"author": "Visual Studio Code Team",
"license": "MIT",
"dependencies": {
"fast-myers-diff": "^3.0.1",
"sha.js": "^2.4.11",
"vscode-languageclient": "7.0.0"
},
Expand Down
22 changes: 11 additions & 11 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ export function isInteractiveCell(cellUri: Uri): boolean {
);
}

export function splitLines(
str: string,
splitOptions: { trim?: boolean; removeEmptyEntries?: boolean } = { removeEmptyEntries: true, trim: true }
): string[] {
export function splitLines(str: string): string[] {
let lines = str.split(/\r?\n/g);
if (splitOptions && splitOptions.trim) {
lines = lines.map((line) => line.trim());
}
if (splitOptions && splitOptions.removeEmptyEntries) {
lines = lines.filter((line) => line.length > 0);
}
return lines;
return lines.slice(0, lines.length - 1); // Skip last empty item
}

export function score(document: TextDocument, selector: DocumentSelector): number {
return languages.match(selector, document);
}

export function findLastIndex<T>(array: Array<T>, predicate: (e: T) => boolean) {
for (let i = array.length - 1; i >= 0; i--) {
if (predicate(array[i])) {
return i;
}
}
return -1;
}
749 changes: 525 additions & 224 deletions src/notebookConcatDocument.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/notebookConcatLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class NotebookConcatLine implements vscode.TextLine {
private _firstNonWhitespaceIndex: number | undefined;
private _isEmpty: boolean | undefined;

constructor(private _contents: string, private _line: number, private _offset: number) {
constructor(public cellUri: vscode.Uri, private _contents: string, private _line: number, private _offset: number) {
this._range = new vscode.Range(new vscode.Position(_line, 0), new vscode.Position(_line, _contents.length));
this._rangeWithLineBreak = new vscode.Range(this.range.start, new vscode.Position(_line, _contents.length + 1));
}
Expand Down
314 changes: 152 additions & 162 deletions src/notebookConverter.ts

Large diffs are not rendered by default.

199 changes: 102 additions & 97 deletions src/notebookMiddlewareAddon.ts

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions src/notebookWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,25 @@ export class NotebookWrapper implements vscode.Disposable {
public getText(range?: vscode.Range) {
return this.concatDocument.getText(range);
}
public locationAt(positionOrRange: vscode.Range | vscode.Position) {
return this.concatDocument.locationAt(positionOrRange);
public notebookLocationAt(positionOrRange: vscode.Range | vscode.Position) {
return this.concatDocument.notebookLocationAt(positionOrRange);
}
public positionAt(offsetOrPosition: number | vscode.Position | vscode.Location) {
return this.concatDocument.positionAt(offsetOrPosition);
}
public offsetAt(position: vscode.Position | vscode.Location) {
return this.concatDocument.offsetAt(position);
public concatPositionAt(location: vscode.Location) {
return this.concatDocument.concatPositionAt(location);
}
public getConcatDocument(): vscode.TextDocument {
return this.concatDocument;
}
public contains(cellUri: vscode.Uri) {
return this.concatDocument.contains(cellUri);
}
public rangeOf(cellUri: vscode.Uri) {
return this.concatDocument.rangeOf(cellUri);
public concatRangeOf(cellUri: vscode.Uri) {
return this.concatDocument.concatRangeOf(cellUri);
}
public realRangeOf(cellUri: vscode.Uri) {
return this.concatDocument.realRangeOf(cellUri);
}
public cellOffsetAt(offset: number) {
return this.concatDocument.cellOffsetAt(offset);
public notebookOffsetAt(cellUri: vscode.Uri, offset: number) {
return this.concatDocument.notebookOffsetAt(cellUri, offset);
}
}
Loading