refactor(misc): Move source and completion mappings to parent using context

Also change most consumers to use the context value
This commit is contained in:
2020-10-05 20:47:49 +05:30
parent c4e8cf7fce
commit 1741826d96
3 changed files with 34 additions and 5 deletions
+10 -3
View File
@@ -10,12 +10,14 @@ import {
import { sourceMapping } from "../../logic/sourceMapping";
import {
completionMapping,
useCompletionMapping,
ICompletionDetail,
ICompletionMapping,
} from "../../logic/completionMapping";
function getCompletionFromSourceToken(
matcheeToken: Token
matcheeToken: Token,
completionMapping: ICompletionMapping
): ICompletionDetail | null {
const matchingSourceDetails = sourceMapping.mappingArray.find(
({ token: tmpToken }) => matcheeToken === tmpToken
@@ -120,13 +122,18 @@ function TokenRenderer({
isLastTokenInLine,
getTokenProps,
}: ITokenRendererProps) {
const completionMapping = useCompletionMapping();
const refFn = sourceMapping.registerToken(token);
if (isLastTokenInLine) {
sourceMapping.registerLineEnd();
}
const onClickToken = (tmpToken: Token) => {
const matchingCompletion = getCompletionFromSourceToken(tmpToken);
const matchingCompletion = getCompletionFromSourceToken(
tmpToken,
completionMapping
);
if (matchingCompletion !== null) {
console.log(
`Clicked: ${tmpToken.content} => Completion (${matchingCompletion.completionType},${matchingCompletion.completionValueString})`