-
Notifications
You must be signed in to change notification settings - Fork 400
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/file-search-support-absolute-path
- Loading branch information
Showing
31 changed files
with
1,981 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 79 additions & 24 deletions
103
packages/ai-native/src/browser/contrib/intelligent-completions/source/line-change.source.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,102 @@ | ||
import { Injectable } from '@opensumi/di'; | ||
import { AINativeSettingSectionsId, ECodeEditsSourceTyping, IDisposable } from '@opensumi/ide-core-common'; | ||
import { ICursorPositionChangedEvent, Position } from '@opensumi/ide-monaco'; | ||
import { ICursorPositionChangedEvent, IModelContentChangedEvent } from '@opensumi/ide-monaco'; | ||
import { | ||
autorunDelta, | ||
derivedHandleChanges, | ||
observableFromEvent, | ||
recomputeInitiallyAndOnChange, | ||
} from '@opensumi/ide-monaco/lib/common/observable'; | ||
|
||
import { BaseCodeEditsSource } from './base'; | ||
|
||
export interface ILineChangeData { | ||
currentLineNumber: number; | ||
preLineNumber?: number; | ||
change?: IModelContentChangedEvent; | ||
} | ||
|
||
@Injectable({ multiple: true }) | ||
export class LineChangeCodeEditsSource extends BaseCodeEditsSource { | ||
public priority = 2; | ||
|
||
private prePosition = this.monacoEditor.getPosition(); | ||
|
||
public mount(): IDisposable { | ||
const modelContentChangeObs = observableFromEvent<IModelContentChangedEvent>( | ||
this, | ||
this.monacoEditor.onDidChangeModelContent, | ||
(event: IModelContentChangedEvent) => event, | ||
); | ||
const positionChangeObs = observableFromEvent<ICursorPositionChangedEvent>( | ||
this, | ||
this.monacoEditor.onDidChangeCursorPosition, | ||
(event: ICursorPositionChangedEvent) => event, | ||
); | ||
|
||
const latestModelContentChangeObs = derivedHandleChanges( | ||
{ | ||
owner: this, | ||
createEmptyChangeSummary: () => ({ change: undefined }), | ||
handleChange: (ctx, changeSummary: { change: IModelContentChangedEvent | undefined }) => { | ||
// 如果只是改了光标则设置 change 为空,避免获取到缓存的 change | ||
if (ctx.didChange(positionChangeObs)) { | ||
changeSummary.change = undefined; | ||
} else { | ||
changeSummary.change = modelContentChangeObs.get(); | ||
} | ||
return true; | ||
}, | ||
}, | ||
(reader, changeSummary) => { | ||
positionChangeObs.read(reader); | ||
modelContentChangeObs.read(reader); | ||
return changeSummary.change; | ||
}, | ||
); | ||
|
||
this.addDispose(recomputeInitiallyAndOnChange(latestModelContentChangeObs)); | ||
|
||
let lastModelContent: IModelContentChangedEvent | undefined; | ||
this.addDispose( | ||
this.monacoEditor.onDidChangeCursorPosition((event: ICursorPositionChangedEvent) => { | ||
const currentPosition = event.position; | ||
if (this.prePosition && this.prePosition.lineNumber !== currentPosition.lineNumber) { | ||
this.doTrigger(currentPosition); | ||
this.prePosition = currentPosition; | ||
} | ||
/** | ||
* 由于 monaco 的 changeModelContent 事件比 changeCursorPosition 事件先触发,所以这里需要拿上一次的值进行消费 | ||
* 否则永远返回 undefined | ||
*/ | ||
autorunDelta(latestModelContentChangeObs, ({ lastValue }) => { | ||
lastModelContent = lastValue; | ||
}), | ||
); | ||
return this; | ||
} | ||
|
||
protected doTrigger(position: Position) { | ||
const isLineChangeEnabled = this.preferenceService.getValid(AINativeSettingSectionsId.CodeEditsLineChange, false); | ||
this.addDispose( | ||
autorunDelta(positionChangeObs, ({ lastValue, newValue }) => { | ||
const contentChange = lastModelContent; | ||
|
||
if (!isLineChangeEnabled || !position) { | ||
return; | ||
} | ||
const isLineChangeEnabled = this.preferenceService.getValid( | ||
AINativeSettingSectionsId.CodeEditsLineChange, | ||
false, | ||
); | ||
if (!isLineChangeEnabled) { | ||
return false; | ||
} | ||
|
||
this.setBean({ | ||
typing: ECodeEditsSourceTyping.LineChange, | ||
position, | ||
data: { | ||
preLineNumber: this.prePosition?.lineNumber, | ||
currentLineNumber: position.lineNumber, | ||
}, | ||
}); | ||
const prePosition = lastValue?.position; | ||
const currentPosition = newValue?.position; | ||
if (prePosition && prePosition.lineNumber !== currentPosition?.lineNumber) { | ||
this.setBean({ | ||
typing: ECodeEditsSourceTyping.LineChange, | ||
position: currentPosition, | ||
data: { | ||
preLineNumber: prePosition.lineNumber, | ||
currentLineNumber: currentPosition.lineNumber, | ||
change: contentChange, | ||
}, | ||
}); | ||
} | ||
|
||
// 消费完之后设置为 undefined,避免下次获取到缓存的值 | ||
lastModelContent = undefined; | ||
}), | ||
); | ||
|
||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Container, URI, ViewRender } from '@difizen/mana-app'; | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
import { useInjectable } from '@opensumi/ide-core-browser'; | ||
import { ReactEditorComponent } from '@opensumi/ide-editor/lib/browser/types'; | ||
|
||
import { LibroVersionManager } from './libro/diff-view/libro-version-manager'; | ||
import { AIStudioLibroVersionView } from './libro/diff-view/libro-version-view'; | ||
import { ContentLoaderType, ManaContainer } from './mana'; | ||
|
||
export const LibroVersionPreview: ReactEditorComponent = ({ resource }) => { | ||
const uri = resource.uri; | ||
const originalUri = uri.scheme === 'diff' ? new URI(decodeURIComponent(uri.getParsedQuery().original)) : undefined; | ||
const targetUri = uri.scheme === 'diff' ? new URI(decodeURIComponent(uri.getParsedQuery().modified)) : undefined; | ||
const manaContainer = useInjectable<Container>(ManaContainer); | ||
const libroVersionManager = manaContainer.get(LibroVersionManager); | ||
const [versionView, setVersionView] = useState<AIStudioLibroVersionView>(); | ||
|
||
useEffect(() => { | ||
libroVersionManager | ||
.getOrCreateView({ | ||
resource: uri.toString(), | ||
loadType: ContentLoaderType, | ||
originalUri, | ||
targetUri, | ||
}) | ||
.then((view) => { | ||
setVersionView(view); | ||
}); | ||
}, [uri]); | ||
|
||
return <div className='libro-version'>{versionView && <ViewRender view={versionView}></ViewRender>}</div>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export const LIBRO_COMPONENTS_ID = 'opensumi:libro'; | ||
export const LIBRO_COMPONENT_ID = 'opensumi:libro'; | ||
export const LIBRO_PREVIEW_COMPONENT_ID = 'opensumi:libro-preview'; | ||
export const LIBRO_DIFF_COMPONENT_ID = 'opensumi:libro-diff'; | ||
export const LIBRO_COMPONENTS_SCHEME_ID = 'ipynb'; |
Oops, something went wrong.