fix: Query missing in AUTO_COMPLETE_SHOW event (#24898)
## Description Query missing in AUTO_COMPLETE_SHOW event #### PR fixes following issue(s) Fixes #23838 #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] Manual - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
This commit is contained in:
parent
87b60908a4
commit
499de5a5b1
|
|
@ -4,7 +4,6 @@ import type { Server, Def } from "tern";
|
|||
import type { Hint, Hints } from "codemirror";
|
||||
import type CodeMirror from "codemirror";
|
||||
import {
|
||||
getDynamicBindings,
|
||||
getDynamicStringSegments,
|
||||
isDynamicValue,
|
||||
} from "utils/DynamicBindingUtils";
|
||||
|
|
@ -204,6 +203,8 @@ class CodeMirrorTernService {
|
|||
const cursor = cm.getCursor();
|
||||
const { extraChars } = this.getFocusedDocValueAndPos(doc);
|
||||
|
||||
const query = this.getQueryForAutocomplete(cm);
|
||||
|
||||
let completions: Completion[] = [];
|
||||
let after = "";
|
||||
const { end, start } = data;
|
||||
|
|
@ -309,13 +310,14 @@ class CodeMirrorTernService {
|
|||
list: completions,
|
||||
selectedHint: indexToBeSelected,
|
||||
lineValue,
|
||||
query: this.getQueryForAutocomplete(cm),
|
||||
};
|
||||
let tooltip: HTMLElement | undefined = undefined;
|
||||
const CodeMirror = getCodeMirrorNamespaceFromEditor(cm);
|
||||
|
||||
CodeMirror.on(obj, "shown", () => {
|
||||
AnalyticsUtil.logEvent("AUTO_COMPLETE_SHOW", {
|
||||
query: getDynamicBindings(lineValue)?.jsSnippets[0],
|
||||
query,
|
||||
numberOfResults: completions.filter(
|
||||
(completion) => !completion.isHeader,
|
||||
).length,
|
||||
|
|
@ -380,15 +382,19 @@ class CodeMirrorTernService {
|
|||
// When a function is picked, move the cursor between the parenthesis
|
||||
const CodeMirror = getCodeMirrorNamespaceFromEditor(cm);
|
||||
CodeMirror.on(hints, "pick", (selected: CommandsCompletion) => {
|
||||
const hintsWithoutHeaders = hints.list.filter(
|
||||
(h: Record<string, unknown>) => h.isHeader !== true,
|
||||
);
|
||||
|
||||
const selectedResultIndex = findIndex(
|
||||
hints.list,
|
||||
hintsWithoutHeaders,
|
||||
(item: Record<string, unknown>) =>
|
||||
item.displayText === selected.displayText,
|
||||
);
|
||||
|
||||
AnalyticsUtil.logEvent("AUTO_COMPLETE_SELECT", {
|
||||
selectedResult: selected.text,
|
||||
query: getDynamicBindings(hints.lineValue)?.jsSnippets[0],
|
||||
query: hints.query,
|
||||
selectedResultIndex,
|
||||
selectedResultType: selected.type,
|
||||
isBestMatch:
|
||||
|
|
@ -613,6 +619,7 @@ class CodeMirrorTernService {
|
|||
value: string;
|
||||
end: { line: number; ch: number };
|
||||
extraChars: number;
|
||||
isSingleDynamicValue?: boolean;
|
||||
} {
|
||||
const cursor = doc.doc.getCursor("end");
|
||||
const value = this.docValue(doc);
|
||||
|
|
@ -628,6 +635,7 @@ class CodeMirrorTernService {
|
|||
ch: cursor.ch,
|
||||
},
|
||||
extraChars,
|
||||
isSingleDynamicValue: isDynamicValue(value),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -886,6 +894,29 @@ class CodeMirrorTernService {
|
|||
setEntityInformation(entityInformation: FieldEntityInformation) {
|
||||
this.fieldEntityInformation = entityInformation;
|
||||
}
|
||||
|
||||
getQueryForAutocomplete(cm: CodeMirror.Editor) {
|
||||
const doc = this.findDoc(cm.getDoc());
|
||||
const lineValue = this.lineValue(doc);
|
||||
const { end, extraChars, isSingleDynamicValue } =
|
||||
this.getFocusedDocValueAndPos(doc);
|
||||
let extraCharsInString = extraChars;
|
||||
const endOfString = end.ch + extraChars;
|
||||
|
||||
if (isSingleDynamicValue) {
|
||||
extraCharsInString += 2;
|
||||
}
|
||||
|
||||
const stringFromEndCh = lineValue.substring(
|
||||
extraCharsInString,
|
||||
endOfString,
|
||||
);
|
||||
|
||||
const splitBySpace = stringFromEndCh.split(" ");
|
||||
const query = splitBySpace[splitBySpace.length - 1];
|
||||
|
||||
return query;
|
||||
}
|
||||
}
|
||||
|
||||
export const createCompletionHeader = (name: string): Completion => ({
|
||||
|
|
|
|||
|
|
@ -191,7 +191,7 @@ describe("Tern server", () => {
|
|||
MockCodemirrorEditor.getCursor.mockReturnValueOnce(
|
||||
testCase.input.codeEditor.cursor,
|
||||
);
|
||||
MockCodemirrorEditor.getDoc.mockReturnValueOnce(
|
||||
MockCodemirrorEditor.getDoc.mockReturnValue(
|
||||
testCase.input.codeEditor.doc,
|
||||
);
|
||||
MockCodemirrorEditor.getTokenAt.mockReturnValueOnce({
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user