generated from scale-tone/durable-mvc-starter
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c153ba
commit 9a4bf8b
Showing
21 changed files
with
1,159 additions
and
780 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
vscode-web-ext/src/web/core/cSharpFunctionProjectParser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { FunctionsMap } from "./FunctionsMap"; | ||
import { getCodeInBrackets, posToLineNr, removeNamespace } from "./traverseFunctionProjectUtils"; | ||
|
||
import { FunctionProjectCodeParser } from "./functionProjectCodeParser"; | ||
|
||
export class CSharpFunctionProjectParser extends FunctionProjectCodeParser { | ||
|
||
protected async getFunctionsAndTheirCodesAsync(functionNames: string[], hostJsonFolder: string): Promise<{ name: string; code: string; filePath: string; pos: number; lineNr: number; }[]> { | ||
|
||
const promises = functionNames.map(async name => { | ||
|
||
const match = await this._fileSystemWrapper.findFileRecursivelyAsync(hostJsonFolder, '.+\\.cs$', true, this.getFunctionStartRegex(name)); | ||
|
||
if (!match) { | ||
return undefined; | ||
} | ||
|
||
const pos = !match.pos ? 0 : match.pos; | ||
const lineNr = posToLineNr(match.code, pos); | ||
const code = getCodeInBrackets(match.code!, match.pos! + match.length!, '{', '}', '\n').code; | ||
|
||
return { name, code, filePath: match.filePath, pos, lineNr }; | ||
}); | ||
|
||
return (await Promise.all(promises)).filter(f => !!f) as any; | ||
} | ||
|
||
protected async traverseProjectCode(projectFolder: string): Promise<FunctionsMap> { | ||
|
||
const result: any = {}; | ||
|
||
const fileNameRegex = new RegExp('.+\\.cs$', 'i'); | ||
|
||
for await (const func of this._fileSystemWrapper.findFunctionsRecursivelyAsync(projectFolder, fileNameRegex, this.getFunctionAttributeRegex())) { | ||
|
||
const bindings = this.tryExtractBindings(func.declarationCode); | ||
|
||
if ( !( | ||
bindings.some(b => b.type === 'orchestrationTrigger') || | ||
bindings.some(b => b.type === 'entityTrigger') || | ||
bindings.some(b => b.type === 'activityTrigger') | ||
)) { | ||
|
||
// Also trying to extract multiple output bindings | ||
bindings.push(...await this.extractOutputBindings(projectFolder, func.declarationCode, fileNameRegex)); | ||
} | ||
|
||
result[func.functionName] = { | ||
|
||
filePath: func.filePath, | ||
pos: func.pos, | ||
lineNr: func.lineNr, | ||
|
||
bindings: [...bindings] | ||
}; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
private async extractOutputBindings(projectFolder: string, functionCode: string, fileNameRegex: RegExp): Promise<{ type: string, direction: string }[]> { | ||
|
||
const returnTypeMatch = this.functionReturnTypeRegex.exec(functionCode); | ||
if (!returnTypeMatch) { | ||
return []; | ||
} | ||
|
||
const returnTypeName = removeNamespace(returnTypeMatch[3]); | ||
if (!returnTypeName) { | ||
return []; | ||
} | ||
|
||
const returnTypeDefinition = await this._fileSystemWrapper.findFileRecursivelyAsync(projectFolder, fileNameRegex, true, this.getClassDefinitionRegex(returnTypeName)); | ||
if (!returnTypeDefinition) { | ||
return []; | ||
} | ||
|
||
const classBody = getCodeInBrackets(returnTypeDefinition.code!, (returnTypeDefinition.pos ?? 0) + (returnTypeDefinition.length ?? 0), '{', '}'); | ||
if (!classBody.code) { | ||
return []; | ||
} | ||
|
||
return this.tryExtractBindings(classBody.code); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
vscode-web-ext/src/web/core/fSharpFunctionProjectParser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { FunctionsMap } from "./FunctionsMap"; | ||
import { getCodeInBrackets, posToLineNr } from "./traverseFunctionProjectUtils"; | ||
|
||
import { RegExAndPos } from "./fileSystemWrapperBase"; | ||
import { FunctionProjectCodeParser } from "./functionProjectCodeParser"; | ||
|
||
export class FSharpFunctionProjectParser extends FunctionProjectCodeParser { | ||
|
||
protected async getFunctionsAndTheirCodesAsync(functionNames: string[], hostJsonFolder: string): Promise<{ name: string; code: string; filePath: string; pos: number; lineNr: number; }[]> { | ||
|
||
const promises = functionNames.map(async name => { | ||
|
||
const match = await this._fileSystemWrapper.findFileRecursivelyAsync(hostJsonFolder, '.+\\.fs$', true, this.getFunctionStartRegex(name)); | ||
|
||
if (!match) { | ||
return undefined; | ||
} | ||
|
||
const code = getCodeInBrackets(match.code!, match.pos! + match.length!, '{', '}', '\n').code; | ||
const pos = !match.pos ? 0 : match.pos; | ||
const lineNr = posToLineNr(match.code, pos); | ||
|
||
return { name, code, filePath: match.filePath, pos, lineNr }; | ||
}); | ||
|
||
return (await Promise.all(promises)).filter(f => !!f) as any; | ||
} | ||
|
||
protected async traverseProjectCode(projectFolder: string): Promise<FunctionsMap> { | ||
|
||
const result: any = {}; | ||
|
||
for await (const func of this._fileSystemWrapper.findFunctionsRecursivelyAsync(projectFolder, new RegExp('.+\\.fs$', 'i'), this.getFunctionAttributeRegex())) { | ||
|
||
const bindings = this.tryExtractBindings(func.declarationCode); | ||
|
||
result[func.functionName] = { | ||
|
||
filePath: func.filePath, | ||
pos: func.pos, | ||
lineNr: func.lineNr, | ||
|
||
bindings: [...bindings] | ||
}; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
protected getFunctionAttributeRegex(): RegExAndPos { | ||
return { | ||
regex: new RegExp(`\\[<\\s*Function(Name)?\\s*\\((["\\w\\s\\.\\(\\)-]+)\\)`, 'g'), | ||
pos: 2 | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as fileSystem from 'fs'; | ||
import * as path from 'path'; | ||
import { FileSystemWrapperBase } from './fileSystemWrapperBase'; | ||
|
||
// Implements common filesystem routines via 'fs' module | ||
export class FileSystemWrapper extends FileSystemWrapperBase { | ||
|
||
public joinPath(path1: string, path2: string): string { | ||
|
||
return path.join(path1, path2); | ||
} | ||
|
||
public dirName(path1: string): string { | ||
|
||
return path.dirname(path1); | ||
} | ||
|
||
public async readFile(path: string): Promise<string> { | ||
|
||
return await fileSystem.promises.readFile(path, { encoding: 'utf8' }); | ||
} | ||
|
||
public async isDirectory(path: string): Promise<boolean> { | ||
|
||
return (await fileSystem.promises.lstat(path)).isDirectory(); | ||
} | ||
|
||
public async readDir(path: string): Promise<string[]> { | ||
|
||
return await fileSystem.promises.readdir(path); | ||
} | ||
|
||
public async pathExists(path: string): Promise<boolean> { | ||
|
||
return fileSystem.existsSync(path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { FunctionsMap } from "./FunctionsMap"; | ||
|
||
import { FunctionProjectParserBase } from './functionProjectParserBase'; | ||
import { RegExAndPos } from "./fileSystemWrapperBase"; | ||
|
||
export abstract class FunctionProjectCodeParser extends FunctionProjectParserBase { | ||
|
||
public async traverseFunctions(projectFolder: string): Promise<FunctionsMap>{ | ||
|
||
let functions: FunctionsMap; | ||
|
||
functions = await this.traverseProjectCode(projectFolder); | ||
|
||
// Now enriching it with more info extracted from code | ||
functions = await this.mapOrchestratorsAndActivitiesAsync(functions, projectFolder); | ||
|
||
return functions; | ||
} | ||
|
||
protected abstract traverseProjectCode(projectFolder: string): Promise<FunctionsMap>; | ||
|
||
protected getFunctionStartRegex(funcName: string): RegExp { | ||
return new RegExp(`FunctionName(Attribute)?\\s*\\(\\s*(nameof\\s*\\(\\s*|["'\`]|[\\w\\s\\.]+\\.\\s*)${funcName}\\s*["'\`\\)]{1}`) | ||
} | ||
|
||
protected getFunctionAttributeRegex(): RegExAndPos { | ||
return { | ||
regex: new RegExp(`\\[\\s*Function(Name)?(Attribute)?\\s*\\((["\\w\\s\\.\\(\\)-]+)\\)\\s*\\]`, 'g'), | ||
pos: 3 | ||
}; | ||
} | ||
} |
Oops, something went wrong.