Skip to content

Commit

Permalink
chore: add line change data
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricbet committed Oct 22, 2024
1 parent 4034a03 commit a9b2e78
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IRange, InlineCompletion } from '@opensumi/ide-monaco';

import type { ILineChangeData } from './source/line-change.source';
import type { ILinterErrorData } from './source/lint-error.source';

export interface IIntelligentCompletionsResult<T = any> {
Expand All @@ -22,7 +23,7 @@ export type ICodeEditsContextBean =
}
| {
typing: ECodeEditsSource.LineChange;
data: unknown;
data: ILineChangeData;
};

export interface ICodeEdit {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
import { Injectable } from '@opensumi/di';
import { IDisposable } from '@opensumi/ide-core-common';
import { ICursorPositionChangedEvent } from '@opensumi/ide-monaco';
import { ICursorPositionChangedEvent, Position } from '@opensumi/ide-monaco';

import { ECodeEditsSource } from '../index';

import { BaseCodeEditsSource } from './base';

export interface ILineChangeData {
currentLineNumber: number;
preLineNumber?: number;
}

@Injectable({ multiple: true })
export class LineChangeCodeEditsSource extends BaseCodeEditsSource {
public priority = 2;

public mount(): IDisposable {
let prePosition = this.monacoEditor.getPosition();
private prePosition = this.monacoEditor.getPosition();

public mount(): IDisposable {
this.addDispose(
this.monacoEditor.onDidChangeCursorPosition((event: ICursorPositionChangedEvent) => {
const currentPosition = event.position;
if (prePosition && prePosition.lineNumber !== currentPosition.lineNumber) {
this.doTrigger();
if (this.prePosition && this.prePosition.lineNumber !== currentPosition.lineNumber) {
this.doTrigger(currentPosition);
this.prePosition = currentPosition;
}
prePosition = currentPosition;
}),
);
return this;
}

private lastEditTime: number | null = null;
protected doTrigger() {
const position = this.monacoEditor.getPosition();
protected doTrigger(position: Position) {
if (!position) {
return;
}
Expand All @@ -41,7 +45,10 @@ export class LineChangeCodeEditsSource extends BaseCodeEditsSource {
this.lastEditTime = currentTime;
this.launchProvider(this.monacoEditor, position, {
typing: ECodeEditsSource.LineChange,
data: {},
data: {
preLineNumber: this.prePosition?.lineNumber,
currentLineNumber: position.lineNumber,
},
});
}
}

0 comments on commit a9b2e78

Please sign in to comment.