Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Bajdzis committed Feb 26, 2021
1 parent 9d124fe commit b4637a1
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 26 deletions.
26 changes: 15 additions & 11 deletions src/store/dependencies/files/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { DirectoriesInfo } from '../../../fileInfo/getSiblingInfo';
import { getFilesContentAsTemplate } from '../../../fileSystem/getFilesContentAsTemplate';
import { getRelativePath } from '../../../fileSystem/getRelativePath';
import { generateFileAction, setDataAction } from '../../../reactViews/apps/chooseFiles/actions/action';
import { compareTree, filterTree } from '../../../symbolInformation/compareTree';
import { compareTree, createTemplateInTree, filterTree } from '../../../symbolInformation/compareTree';
import { getFileSymbols } from '../../../symbolInformation/getFileSymbols';
import { joinSymbolToString } from '../../../symbolInformation/joinSymbolToString';
import { joinSymbolToString, treeSymbolToFlattArray } from '../../../symbolInformation/joinSymbolToString';
import { compareVariableTemplate } from '../../../variableTemplate/compareVariableTemplate';
import { renderVariableTemplate } from '../../../variableTemplate/renderVariableTemplate';
import { WebViewReact } from '../webView/webViewReact';
Expand Down Expand Up @@ -82,8 +82,8 @@ export class Files {
}

async getContentBySibling(createdItemUri: vscode.Uri): Promise<string> {
// const relativePath = getRelativePath(createdItemUri.fsPath);
// const infoAboutNewFile = getInfoAboutPath(relativePath);
const relativePath = getRelativePath(createdItemUri.fsPath);
const infoAboutNewFile = getInfoAboutPath(relativePath);
const parentDir = path.dirname(createdItemUri.fsPath);

const fileToSkip = path.basename(createdItemUri.fsPath);
Expand All @@ -104,19 +104,23 @@ export class Files {
const files = contents.map(siblingFile => {
const filePath = path.join(parentDir, siblingFile);
const fileUri = vscode.Uri.file(filePath);
const infoAboutFilePath = getInfoAboutPath(getRelativePath(filePath));
console.log( {fileUri} );
return getFileSymbols(fileUri);
return getFileSymbols(fileUri).then(data => createTemplateInTree([data], [infoAboutFilePath])[0]);
});

const filesContent = await Promise.all(files).then(data => {

return compareTree(data);
const filesContent = await Promise.all(files)
.then(data => compareTree(data))
.then(data => filterTree(data, 0.75))
.then(data => treeSymbolToFlattArray(data));

}).then(data => filterTree(data, 0.75));

console.log({ filesContent });
console.log({ files, filesContent });

const content = joinSymbolToString(filesContent);
const content = joinSymbolToString(filesContent, [infoAboutNewFile]);


// const [baseFile, ...otherFiles] = contents;
// const linesToGenerate: string[] = baseFile
// .filter((line) => this.allFilesIncludeThisLine(otherFiles, line));
Expand Down
67 changes: 64 additions & 3 deletions src/symbolInformation/compareTree.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { PathInfo } from '../fileInfo/getInfoAboutPath';
import { compareVariableTemplate } from '../variableTemplate/compareVariableTemplate';
import { createVariableTemplate } from '../variableTemplate/createVariableTemplate';
import { FileSymbol } from './getFileSymbols';


Expand All @@ -7,11 +10,59 @@ export interface FileSymbolCompare {
children: FileSymbolCompare[];
}

function compareFileSymbol (elem1:FileSymbol, elem2:FileSymbol) {

function haveSameKind (elem1:FileSymbol, elem2:FileSymbol) {
return elem1.kind === elem2.kind ;
}

function haveSameValue (elem1:FileSymbol, elem2:FileSymbol) {

if(elem1.children.length > 0 && elem2.children.length > 0) {
return elem1.kind === elem2.kind;
return true;
}
return elem1.kind === elem2.kind && elem1.value === elem2.value;
return compareVariableTemplate(elem1.value, elem2.value);
}

// function haveSameFirstChildren (elem1:FileSymbol, elem2:FileSymbol) {

// if(elem1.children.length === 0 && elem2.children.length === 0) {
// return true;
// }

// if(elem1.children.length > 0 && elem2.children.length > 0) {
// return haveSameKind(elem1.children[0], elem2.children[0]) && haveSameValue(elem1.children[0], elem2.children[0]);
// }

// return false;
// }

// function haveSameLastChildren (elem1:FileSymbol, elem2:FileSymbol) {

// if(elem1.children.length === 0 && elem2.children.length === 0) {
// return true;
// }

// if(elem1.children.length > 0 && elem2.children.length > 0) {
// return haveSameKind(elem1.children[elem1.children.length-1], elem2.children[elem2.children.length-1]) && haveSameValue(elem1.children[elem1.children.length-1], elem2.children[elem2.children.length-1]);
// }

// return false;
// }


function compareFileSymbol (elem1:FileSymbol, elem2:FileSymbol) {
if(!haveSameKind(elem1, elem2)){
return false;
}

// if(!haveSameFirstChildren(elem1, elem2)){
// return false;
// }

// if(!haveSameLastChildren(elem1, elem2)){
// return false;
// }
return haveSameValue(elem1, elem2);
}

export function compareTree(trees: FileSymbol[], isSameElement = compareFileSymbol, numberOfFiles = trees.length): FileSymbolCompare[] {
Expand Down Expand Up @@ -53,3 +104,13 @@ export function filterTree(trees: FileSymbolCompare[], minPercentValue = 0.8): F
children: filterTree(tree.children, minPercentValue)
}));
}


export function createTemplateInTree(trees: FileSymbol[], infoAboutFile: PathInfo[]): FileSymbol[] {

return trees.map(tree => ({
...tree,
value: createVariableTemplate(tree.value, infoAboutFile),
children: createTemplateInTree(tree.children, infoAboutFile)
}));
}
19 changes: 7 additions & 12 deletions src/symbolInformation/joinSymbolToString.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
import { PathInfo } from '../fileInfo/getInfoAboutPath';
import { renderVariableTemplate } from '../variableTemplate/renderVariableTemplate';
import { FileSymbolCompare } from './compareTree';




export function joinSymbolToFlattArray(symbols: FileSymbolCompare[]): FileSymbolCompare[] {
export function treeSymbolToFlattArray(symbols: FileSymbolCompare[]): FileSymbolCompare[] {
if(symbols.every(symbol => symbol.children.length === 0)) {
return symbols;
}

const flatten: FileSymbolCompare[] = [];
symbols.forEach(symbol => {


if(symbol.children.length !== 0 ) {

flatten.push(...symbol.children);
}else {

} else {
flatten.push(symbol);
}
});

return joinSymbolToFlattArray(flatten);
return treeSymbolToFlattArray(flatten);
}

export function joinSymbolToString(trees: FileSymbolCompare[]): string {
return joinSymbolToFlattArray(trees).map(item => item.items[0].text).join('');
export function joinSymbolToString(trees: FileSymbolCompare[], infoAboutFile: PathInfo[]): string {
return trees.map(item => renderVariableTemplate(item.items[0].text, infoAboutFile )).join('');
}


0 comments on commit b4637a1

Please sign in to comment.