Skip to content

Commit 3ad64b3

Browse files
committed
Merge branch 'main' into cs-7993-support-multiple-tool-calls-per-ai-response
2 parents 3911dc8 + 052d078 commit 3ad64b3

File tree

11 files changed

+503
-287
lines changed

11 files changed

+503
-287
lines changed

packages/host/app/components/ai-assistant/formatted-message.gts

+1
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,6 @@ export default class FormattedMessage extends Component<FormattedMessageSignatur
125125
scrollbar: {
126126
alwaysConsumeMouseWheel: false,
127127
},
128+
lineNumbers: 'off',
128129
};
129130
}

packages/host/app/components/matrix/room-message-command.gts

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export default class RoomMessageCommand extends Component<Signature> {
6969
scrollbar: {
7070
alwaysConsumeMouseWheel: false,
7171
},
72+
lineNumbers: 'off',
7273
};
7374

7475
private get previewCommandCode() {

packages/host/app/components/operator-mode/code-editor.gts

+32-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import type { MonacoSDK } from '@cardstack/host/services/monaco-service';
3232

3333
import type OperatorModeStateService from '@cardstack/host/services/operator-mode-state-service';
3434

35+
import RecentFilesService from '@cardstack/host/services/recent-files-service';
36+
3537
import BinaryFileInfo from './binary-file-info';
3638

3739
interface Signature {
@@ -54,6 +56,7 @@ export default class CodeEditor extends Component<Signature> {
5456
@service private declare operatorModeStateService: OperatorModeStateService;
5557
@service private declare cardService: CardService;
5658
@service private declare environmentService: EnvironmentService;
59+
@service private declare recentFilesService: RecentFilesService;
5760

5861
@tracked private maybeMonacoSDK: MonacoSDK | undefined;
5962

@@ -122,6 +125,18 @@ export default class CodeEditor extends Component<Signature> {
122125

123126
@cached
124127
private get initialMonacoCursorPosition() {
128+
if (this.codePath) {
129+
let recentFile = this.recentFilesService.findRecentFileByURL(
130+
this.codePath.toString(),
131+
);
132+
if (recentFile?.cursorPosition) {
133+
return new Position(
134+
recentFile.cursorPosition.line,
135+
recentFile.cursorPosition.column,
136+
);
137+
}
138+
}
139+
125140
let loc =
126141
this.args.selectedDeclaration?.path?.node &&
127142
'body' in this.args.selectedDeclaration.path.node &&
@@ -195,6 +210,22 @@ export default class CodeEditor extends Component<Signature> {
195210
}
196211
}
197212

213+
@action
214+
private onCursorPositionChange(position: Position) {
215+
this.selectDeclarationByMonacoCursorPosition(position);
216+
217+
if (!this.codePath) {
218+
return;
219+
}
220+
this.recentFilesService.updateCursorPositionByURL(
221+
this.codePath.toString(),
222+
{
223+
line: position.lineNumber,
224+
column: position.column,
225+
},
226+
);
227+
}
228+
198229
@action
199230
private selectDeclarationByMonacoCursorPosition(position: Position) {
200231
let declarationCursorOn = this.declarations.find(
@@ -303,7 +334,7 @@ export default class CodeEditor extends Component<Signature> {
303334
monacoSDK=this.monacoSDK
304335
language=this.language
305336
initialCursorPosition=this.initialMonacoCursorPosition
306-
onCursorPositionChange=this.selectDeclarationByMonacoCursorPosition
337+
onCursorPositionChange=this.onCursorPositionChange
307338
readOnly=@isReadOnly
308339
editorDisplayOptions=(hash lineNumbersMinChars=3 fontSize=13)
309340
}}

packages/host/app/components/operator-mode/code-submode.gts

+34-12
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ import { and, not, bool, eq } from '@cardstack/boxel-ui/helpers';
2828
import { File } from '@cardstack/boxel-ui/icons';
2929

3030
import {
31+
identifyCard,
3132
isCardDef,
3233
isCardDocumentString,
3334
hasExecutableExtension,
3435
RealmPaths,
36+
isResolvedCodeRef,
3537
type ResolvedCodeRef,
3638
PermissionsContextName,
3739
} from '@cardstack/runtime-common';
@@ -464,15 +466,20 @@ export default class CodeSubmode extends Component<Signature> {
464466
return undefined;
465467
}
466468

467-
private get shouldDisplayPlayground() {
468-
return isCardDef(this.selectedCardOrField?.cardOrField);
469+
private get selectedCardRef(): ResolvedCodeRef | undefined {
470+
let baseDefType = this.selectedCardOrField?.cardOrField;
471+
if (!isCardDef(baseDefType)) {
472+
return undefined;
473+
}
474+
let codeRef = identifyCard(baseDefType);
475+
if (!isResolvedCodeRef(codeRef)) {
476+
return undefined;
477+
}
478+
return codeRef;
469479
}
470480

471481
get showSpecPreview() {
472-
return (
473-
!this.moduleContentsResource.isLoading &&
474-
this.selectedDeclaration?.exportName
475-
);
482+
return this.selectedCardOrField?.exportName;
476483
}
477484

478485
private get itemToDeleteAsCard() {
@@ -489,7 +496,22 @@ export default class CodeSubmode extends Component<Signature> {
489496
}
490497

491498
@action
492-
goToDefinition(
499+
private goToDefinitionAndResetCursorPosition(
500+
codeRef: ResolvedCodeRef | undefined,
501+
localName: string | undefined,
502+
) {
503+
this.goToDefinition(codeRef, localName);
504+
if (this.codePath) {
505+
let urlString = this.codePath.toString();
506+
this.recentFilesService.updateCursorPositionByURL(
507+
urlString.endsWith('gts') ? urlString : `${urlString}.gts`,
508+
undefined,
509+
);
510+
}
511+
}
512+
513+
@action
514+
private goToDefinition(
493515
codeRef: ResolvedCodeRef | undefined,
494516
localName: string | undefined,
495517
) {
@@ -808,7 +830,7 @@ export default class CodeSubmode extends Component<Signature> {
808830
@selectedDeclaration={{this.selectedDeclaration}}
809831
@selectDeclaration={{this.selectDeclaration}}
810832
@delete={{this.setItemToDelete}}
811-
@goToDefinition={{this.goToDefinition}}
833+
@goToDefinition={{this.goToDefinitionAndResetCursorPosition}}
812834
@createFile={{perform this.createFile}}
813835
@openSearch={{search.openSearchToResults}}
814836
/>
@@ -932,7 +954,7 @@ export default class CodeSubmode extends Component<Signature> {
932954
@moduleContentsResource={{this.moduleContentsResource}}
933955
@card={{this.selectedCardOrField.cardOrField}}
934956
@cardTypeResource={{this.selectedCardOrField.cardType}}
935-
@goToDefinition={{this.goToDefinition}}
957+
@goToDefinition={{this.goToDefinitionAndResetCursorPosition}}
936958
@isReadOnly={{this.isReadOnly}}
937959
as |SchemaEditorTitle SchemaEditorPanel|
938960
>
@@ -957,7 +979,7 @@ export default class CodeSubmode extends Component<Signature> {
957979
</:content>
958980
</A.Item>
959981
</SchemaEditor>
960-
{{#if this.shouldDisplayPlayground}}
982+
{{#if this.selectedCardRef}}
961983
<A.Item
962984
class='accordion-item'
963985
@contentClass='accordion-item-content'
@@ -968,8 +990,8 @@ export default class CodeSubmode extends Component<Signature> {
968990
<:title>Playground</:title>
969991
<:content>
970992
<PlaygroundPanel
971-
@moduleContentsResource={{this.moduleContentsResource}}
972-
@cardType={{this.selectedCardOrField.cardType}}
993+
@codeRef={{this.selectedCardRef}}
994+
@isLoadingNewModule={{this.moduleContentsResource.isLoadingNewModule}}
973995
/>
974996
</:content>
975997
</A.Item>

0 commit comments

Comments
 (0)