Skip to content

Commit 2d7d212

Browse files
committed
fix(log-feature): Variable getting its value from a function call
1 parent 85338e6 commit 2d7d212

File tree

8 files changed

+107
-19
lines changed

8 files changed

+107
-19
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to the "turbo-console-log" extension will be documented in this file.
44

5+
## [2.10.5]
6+
7+
### Fixed
8+
9+
- Improved Turbo Console Log to accurately insert log messages for variable assignments, specifically when a variable is assigned a value from a function call in TypeScript and JavaScript files.
10+
511
## [2.10.4]
612

713
### Fixed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "turbo-console-log",
33
"displayName": "Turbo Console Log",
44
"description": "Automating the process of writing meaningful log messages.",
5-
"version": "2.10.4",
5+
"version": "2.10.5",
66
"publisher": "ChakrounAnas",
77
"engines": {
88
"vscode": "^1.50.0"

src/debug-message/js/JSDebugMessage.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -455,35 +455,33 @@ export class JSDebugMessage extends DebugMessage {
455455
const isOpeningCurlyBraceContext = document
456456
.lineAt(multilineParenthesisVariable?.closingContextLine as number)
457457
.text.includes('{');
458-
const isOpeningParenthesisContext = document
459-
.lineAt(selectionLine)
460-
.text.includes('(');
461-
if (isOpeningCurlyBraceContext || isOpeningParenthesisContext) {
462-
if (this.lineCodeProcessing.isAssignedToVariable(currentLineText)) {
458+
if (this.lineCodeProcessing.isAssignedToVariable(currentLineText)) {
459+
if (isOpeningCurlyBraceContext) {
463460
return {
464461
isChecked: true,
465462
metadata: {
466463
openingContextLine: selectionLine,
467464
closingContextLine: closingContextLine(
468465
document,
469466
multilineParenthesisVariable?.closingContextLine as number,
470-
isOpeningCurlyBraceContext
471-
? BracketType.CURLY_BRACES
472-
: BracketType.PARENTHESIS,
467+
BracketType.CURLY_BRACES,
473468
),
474469
} as Pick<LogMessage, 'metadata'>,
475470
};
476471
}
477472
return {
478-
isChecked: true,
479-
metadata: {
480-
openingContextLine:
481-
multilineParenthesisVariable?.openingContextLine as number,
482-
closingContextLine:
483-
multilineParenthesisVariable?.closingContextLine as number,
484-
} as Pick<LogMessage, 'metadata'>,
473+
isChecked: false,
485474
};
486475
}
476+
return {
477+
isChecked: true,
478+
metadata: {
479+
openingContextLine:
480+
multilineParenthesisVariable?.openingContextLine as number,
481+
closingContextLine:
482+
multilineParenthesisVariable?.closingContextLine as number,
483+
} as Pick<LogMessage, 'metadata'>,
484+
};
487485
}
488486
return {
489487
isChecked: false,

src/line-code-processing/js/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export class JSLineCodeProcessing implements LineCodeProcessing {
2121
return false;
2222
}
2323
isAssignedToVariable(loc: string): boolean {
24-
return /(const|let|var).*{?\s*}?=.*/.test(loc);
24+
return /^(?:const|let|var)?\s*(\w+|\$?\w+(\.\w+)*)(\s*{[^}]*}\s*)?\s*=/.test(
25+
loc,
26+
);
2527
}
2628
isAffectationToVariable(loc: string): boolean {
2729
return /.*=.*/.test(loc);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// @ts-nocheck
2+
3+
export function useUserSettings() {
4+
const currencies = useQuery({
5+
enabled: false,
6+
queryFn: () => sdk.unified.getCurrencies(),
7+
queryKey: ['settings', 'currencies'],
8+
});
9+
const setCurrentCurrency = (value: string) => {
10+
setCookie(CURRENCY_COOKIE, value, {
11+
sameSite: 'strict',
12+
secure: true,
13+
});
14+
currencies.refetch();
15+
queryClient.removeQueries({
16+
queryKey: ['lazyProduct'],
17+
type: 'active',
18+
});
19+
setCurrency(value);
20+
};
21+
return { setCurrentCurrency, setCurrentLocale };
22+
}

src/test/integration/js/log-feature/variable/deconstructionVarAssignment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ export default (): void => {
4848
).to.equal(true);
4949
activeTextEditor.selections = [
5050
new vscode.Selection(
51-
new vscode.Position(25, 11),
52-
new vscode.Position(25, 15),
51+
new vscode.Position(25, 10),
52+
new vscode.Position(25, 14),
5353
),
5454
];
5555
await vscode.commands.executeCommand(

src/test/integration/js/log-feature/variable/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import deconstructionVarAssignmentTest from './deconstructionVarAssignment';
33
import deconstructionArgFunction from './deconstructionArgFunction';
44
import primitiveVariableTest from './primitiveVariable';
55
import logLastLineTest from './logLastLine';
6+
import valueFromFunctionCall from './valueFromFunctionCall';
67

78
export default (): void => {
89
describe('Variable context menu', () => {
910
deconstructionVarAssignmentTest();
1011
primitiveVariableTest();
1112
logLastLineTest();
1213
deconstructionArgFunction();
14+
valueFromFunctionCall();
1315
});
1416
};
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import * as vscode from 'vscode';
2+
import Mocha, { it, describe } from 'mocha';
3+
import { expect } from 'chai';
4+
import {
5+
openDocument,
6+
expectActiveTextEditorWithFile,
7+
documentLinesChanged,
8+
NaturalEditorPosition,
9+
naturalEditorLine,
10+
} from '../../../helpers';
11+
import { ProgrammingLanguage } from '../../../../../entities';
12+
13+
export default (): void => {
14+
describe('Variable getting its value from a function call', () => {
15+
Mocha.before(async () => {
16+
await openDocument(
17+
ProgrammingLanguage.JAVASCRIPT,
18+
'log-feature/variable',
19+
'valueFromFunctionCall.ts',
20+
);
21+
});
22+
Mocha.after(async () => {
23+
await vscode.commands.executeCommand(
24+
'workbench.action.closeActiveEditor',
25+
[],
26+
);
27+
});
28+
it('Case 1', async () => {
29+
const { activeTextEditor } = vscode.window;
30+
expectActiveTextEditorWithFile(
31+
activeTextEditor,
32+
'valueFromFunctionCall.ts',
33+
);
34+
if (activeTextEditor) {
35+
activeTextEditor.selections = [
36+
new vscode.Selection(
37+
new NaturalEditorPosition(4, 9),
38+
new NaturalEditorPosition(4, 19),
39+
),
40+
];
41+
await vscode.commands.executeCommand(
42+
'turboConsoleLog.displayLogMessage',
43+
[],
44+
);
45+
await Promise.all(
46+
documentLinesChanged(activeTextEditor.document, [
47+
naturalEditorLine(9),
48+
]),
49+
);
50+
expect(
51+
/console\.log\(.*/.test(
52+
activeTextEditor.document.lineAt(naturalEditorLine(9)).text,
53+
),
54+
).to.equal(true);
55+
}
56+
});
57+
});
58+
};

0 commit comments

Comments
 (0)