8000 Add LLM instructions file suggestion by madmath · Pull Request #669 · Shopify/theme-tools · GitHub
[go: up one dir, main page]

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

Add LLM instructions file suggestion #669

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
b8590e7
wip
karreiro Dec 11, 2024
ab1894f
(wip 2) calling the language model api
karreiro Dec 11, 2024
a9d00c6
(wip 3) sidefix
karreiro Dec 11, 2024
5b6fc33
(wip 4) make sidekick a bit less ugly
karreiro Dec 11, 2024
b65037f
(wip 5) make sidekick a bit less ugly (2)
karreiro Dec 11, 2024
d1c5ad1
Move loading state to title button (#670)
frandiox Dec 12, 2024
4506991
Support multiple suggestions from a single request (#671)
frandiox Dec 12, 2024
e48c237
Bring hover back
karreiro Dec 12, 2024
3ee58bd
Support suggestions on selected code (#672)
frandiox Dec 12, 2024
5783a02
Hide suggestions on code change (#673)
frandiox Dec 12, 2024
4292a57
(wip) updated prompt
karreiro Dec 12, 2024
ebed821
(wip) prompt
karreiro Dec 12, 2024
9fe8f94
(wip) prompt 2
karreiro Dec 12, 2024
7565dca
Add LLM instructions file suggestion
madmath Dec 11, 2024
606f5c1
update llm instructions
madmath Dec 11, 2024
1e8e1c1
8000 New llm instruction file
benjaminsehl Dec 12, 2024
f7b03ac
Add LLM instructions file suggestion
madmath Dec 11, 2024
02c2788
update llm instructions
madmath Dec 11, 2024
2005242
Use diff view for sidefix
frandiox Dec 13, 2024
f945a77
Improve the timing for removing suggestions
frandiox Dec 13, 2024
9b5b55a
Try to improve the prompt
frandiox Dec 13, 2024
b00728b
Update prompt to use tag convention
karreiro Dec 13, 2024
37989c2
Remove duplicated functions; extract file creation to a method because
karreiro Dec 13, 2024
ac395da
Fine tuning prompt
karreiro Dec 13, 2024
76a04a2
Remove unused items
karreiro Dec 13, 2024
1713459
Setup 'vitest' on 'packages/vscode-extension'
karreiro Jan 24, 2025
07126c3
Extract 'isCursor' and 'hasShopifyThemeLoaded' to 'utils.ts'
karreiro Jan 24, 2025
42e6f9f
Extract the logic for showing/hiding the 'Shopify Magic' button to 'u…
karreiro Jan 24, 2025
12a68d2
Removing 'inline completions' support as we are leaning towards 'text…
karreiro Jan 24, 2025
f2e89ec
Fix fs tests on Windows in 'utils.spec.ts'
karreiro Jan 24, 2025
3715a1f
- Extract `.cursorrules/copilot-instructions.md` files creation to 'l…
karreiro Jan 27, 2025
2a639d4
Extract 'RefactorProvider' from 'extensions'
karreiro Jan 27, 2025
4edd360
Extract, improve, and breakdown prompts in 'shopify-magic-prompts'
karreiro Jan 28, 2025
04bada9
Remove 'llm-instructions.template' and make tests run faster
karreiro Jan 28, 2025
425488f
Rename 'Sidekick' to 'Shopify Magic' everywhere
karreiro Jan 28, 2025
141ec78
RefactorProvider.ts -> ShopifyMagicCodeActionProvider.ts
karreiro Jan 28, 2025
e8c7a5b
Former llm-instructions.template and live prompt now share the same l…
karreiro Jan 28, 2025
db2c1d6
- Adjust file create + refine prompt
karreiro Jan 28, 2025
8003761
Improve Dialogs
karreiro Jan 28, 2025
85a8b5b
Add changeset
karreiro Jan 28, 2025
dd4eb4f
Improve 'isInstructionsFileUpdated' function following review suggestion
karreiro Jan 30, 2025
f458ed4
Refine prompt to avoid statements were it keeps the logic
karreiro Jan 30, 2025
9a6647a
Rename 'sideFix' to 'magicFix'
karreiro Jan 30, 2025
c8b67ad
Refine prompt to avoid statements were it keeps the logic [2]
karreiro Jan 31, 2025
6f2b83b
Refine prompt to avoid statements were it keeps the logic [3]
karreiro Feb 10, 2025
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
Prev Previous commit
Next Next commit
Improve the timing for removing suggestions
  • Loading branch information
frandiox authored and karreiro committed Feb 10, 2025
commit f945a77043cbfb5e310d72a54302f852331bd5af
66 changes: 55 additions & 11 deletions packages/vscode-extension/src/node/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ import LiquidFormatter from '../common/formatter';
import { vscodePrettierFormat } from './formatter';
import { getSidekickAnalysis, LiquidSuggestion, log, SidekickDecoration } from './sidekick';

type LiquidSuggestionWithDecorationKey = LiquidSuggestion & { key: string };

const sleep = (ms: number) => new Promise((res) => setTimeout(res, ms));

let $client: LanguageClient | undefined;
let $editor: TextEditor | undefined;
let $decorations: TextEditorDecorationType[] = [];
let $isApplyingSuggestion = false;
let $previousShownConflicts = new Map<string, number>();

async function isShopifyTheme(workspaceRoot: string): Promise<boolean> {
try {
Expand Down Expand Up @@ -210,11 +214,14 @@ export async function activate(context: ExtensionContext) {
}),
);
context.subscriptions.push(
commands.registerCommand('shopifyLiquid.sidefix', async (suggestion: LiquidSuggestion) => {
log('Sidekick is fixing...');
commands.registerCommand(
'shopifyLiquid.sidefix',
async (suggestion: LiquidSuggestionWithDecorationKey) => {
log('Sidekick is fixing...');

applySuggestion(suggestion);
}),
applySuggestion(suggestion);
},
),
);
// context.subscriptions.push(
// languages.registerInlineCompletionItemProvider(
Expand All @@ -224,8 +231,32 @@ export async function activate(context: ExtensionContext) {
// );

context.subscriptions.push(
workspace.onDidChangeTextDocument(() => {
disposeDecorations();
workspace.onDidChangeTextDocument(({ contentChanges, reason, document }) => {
// Each shown suggestion fix is displayed as a conflict in the editor. We want to
// hide all suggestion hints when the user starts typing, as they are no longer
// relevant, but we don't want to remove them on conflict resolution since that
// only means the user has accepted/rejected a suggestion and might continue with
// the other suggestions.
const currentShownConflicts = document.getText().split(conflictMarkerStart).length - 1;

if (
// Ignore when there are no content changes
contentChanges.length > 0 &&
// Ignore when initiating the diff view (it triggers a change event)
!$isApplyingSuggestion &&
// Ignore undo/redos
reason === undefined &&
// Only dispose decorations when there are no conflicts currently shown (no diff views)
// and when there were no conflicts shown previously. This means that the current
// change is not related to a conflict resolution but a manual user input.
currentShownConflicts === 0 &&
!$previousShownConflicts.get(document.fileName)
) {
disposeDecorations();
}

// Store the previous number of conflicts shown for this document.
$previousShownConflicts.set(document.fileName, currentShownConflicts);
}),
);

Expand Down Expand Up @@ -326,12 +357,18 @@ function applyDecorations(decorations: SidekickDecoration[]) {
});
}

async function applySuggestion({ range, newCode }: LiquidSuggestion) {
const conflictMarkerStart = '<<<<<<< Current';
const conflictMarkerMiddle = '=======';
const conflictMarkerEnd = '>>>>>>> Suggested Change';

async function applySuggestion({ key, range, newCode }: LiquidSuggestionWithDecorationKey) {
log('Applying suggestion...');
if (!$editor) {
return;
}

$isApplyingSuggestion = true;

const endLineIndex = range.end.line - 1;
const start = new Position(range.start.line - 1, 0);
const end = new Position(endLineIndex, $editor.document.lineAt(endLineIndex).text.length);
Expand All @@ -340,17 +377,24 @@ async function applySuggestion({ range, newCode }: LiquidSuggestion) {

// Create a merge conflict style text
const conflictText = [
'<<<<<<< Current',
conflictMarkerStart,
oldCode,
'=======',
conflictMarkerMiddle,
newCode.replace(/^/gm, initialIndentation),
'>>>>>>> Suggested Change',
conflictMarkerEnd,
].join('\n');

// Replace the current text with the conflict markers
const edit = new WorkspaceEdit();
edit.replace($editor.document.uri, new Range(start, end), conflictText);
await workspace.applyEdit(edit);

disposeDecorations();
// Only dispose the decoration associated with this suggestion
const decorationIndex = $decorations.findIndex((d) => d.key === key);
if (decorationIndex !== -1) {
$decorations[decorationIndex].dispose();
$decorations.splice(decorationIndex, 1);
}

$isApplyingSuggestion = false;
}
8 changes: 4 additions & 4 deletions packages/vscode-extension/src/node/sidekick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ function buildSidekickDecoration(
new Position(line, 0),
new Position(line, editor.document.lineAt(line).text.length),
),
hoverMessage: createHoverMessage(liquidSuggestion),
hoverMessage: createHoverMessage(type.key, liquidSuggestion),
};

return [{ type, options }];
return [{ type, options }];
}

async function parseChatResponse(chatResponse: LanguageModelChatResponse) {
Expand Down Expand Up @@ -114,8 +114,8 @@ export function log(message?: any, ...optionalParams: any[]) {
console.error(` [Sidekick] ${message}`, ...optionalParams);
}

function createHoverMessage(liquidSuggestion: LiquidSuggestion) {
const hoverUrlArgs = encodeURIComponent(JSON.stringify(liquidSuggestion));
function createHoverMessage(key: string, liquidSuggestion: LiquidSuggestion) {
const hoverUrlArgs = encodeURIComponent(JSON.stringify({ key, ...liquidSuggestion }));
const hoverMessage = new MarkdownString(
`✨ ${liquidSuggestion.suggestion}
\n\n[Quick fix](command:shopifyLiquid.sidefix?${hoverUrlArgs})`,
Expand Down
0