Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private processIdentifier(node, type, deepLayer, prefix: string, baseInfo?, searchRes?) {
if (type === travelMode.GET_DEFINE) {
if (node['type'] === 'Identifier') {
if (baseInfo == undefined || baseInfo.name == undefined || baseInfo.name === '') {
baseInfo = { name: node["name"], isLocal: node['isLocal'] };
} else {
if(baseInfo.identiferStr){
baseInfo.name = baseInfo.name + '.' + baseInfo.identiferStr + '.' + node["name"];
}else{
baseInfo.name = baseInfo.name + '.' + node["name"];
}
}
//搜索
let nodeLoc1 = Location.create(this.docInfo["docUri"], node["loc"]);
if ( this.isInLocation(nodeLoc1, this.searchPosition) ) {
this.posSearchRet = this.createRetSymbol(baseInfo.name, baseInfo.isLocal);
}else{
this.posSearchRet = this.createRetBase(baseInfo.name, baseInfo.isLocal);
}
}
if (node['type'] === 'BinaryExpression') {
// c[ a + b ] = 9 , 搜索a或者b的定义
}
}
if (type === travelMode.FIND_REFS) {
if (node['type'] === 'Identifier') {
if (baseInfo == undefined || baseInfo.name == undefined || baseInfo.name === '') {
baseInfo = { name: node["name"], isLocal: node['isLocal'] };
// Do autocomplete?
const doNotAutoComplete = thisFunc.hidden || thisFunc.name.charAt(0) === '_';
// Get our YYFile Path
const ourPath = path.join(
this.projectDirectory,
'extensions',
yyFile.name,
yyFile.name + '.yy'
);
this.reference.extensionAddExtension(
thisFunc.name,
ourJSDOC,
doNotAutoComplete,
Location.create(URI.file(ourPath).toString(), Range.create(0, 0, 0, 0)),
yyFile.name,
thisFile.filename
);
}
this.reference.extensionRecordSetHash(yyFile.name, thisFile.filename, thisHash);
} else {
// Get our GML File:
const fpath = path.join(this.projectDirectory, 'extensions', yyFile.name, thisFile.filename);
const thisURI = URI.file(fpath);
const extensionFile = await fse.readFile(fpath, 'utf8');
// Check our Hash
const ourHasher = crypto.createHash('sha1');
const thisHash = ourHasher.update(extensionFile).digest('hex');
if (thisExtensionCache && thisExtensionCache[thisFile.filename]) {
private processFunction(node, type, deepLayer: Array, prefix?: string) {
let searchRes = false; //整体检查位置是否在 function 中
let paraRecoder = new Array();
// GET_DEFINE 先判断搜索位置是否在 函数location中
if (type === travelMode.GET_DEFINE) {
let nodeLoc = Location.create(this.docInfo["docUri"], node["loc"]);
searchRes = this.isInLocation(nodeLoc, this.searchPosition);
// 用户点搜索的位置不在本function范围内, 清空数据,返回
if(searchRes == false) {
this.posSearchRet = new Tools.searchRet();
}
}
// 1. 记录函数参数
let searchHitPara = false;
let searchHitParaIdx = 0;
let paramArray = new Array();
for (let idx = 0; idx < node["parameters"].length; idx++) {
let paraNode = node["parameters"][idx];
if(paraNode.type == 'VarargLiteral'){
//可变参数
paramArray.push(paraNode['value']);
for (let instruction of dockerfile.getCOPYs()) {
let flag = instruction.getFromFlag();
if (flag) {
let range = flag.getValueRange();
if (range && range.start.line === position.line && range.start.character <= position.character && position.character <= range.end.character) {
source = flag.getValue();
break;
}
}
}
for (let instruction of dockerfile.getFROMs()) {
let range = instruction.getBuildStageRange();
if (range &&
((range.start.line === position.line && range.start.character <= position.character && position.character <= range.end.character) || (instruction.getBuildStage() === source))) {
return Location.create(uri, range);
}
}
return null;
}
private getDefinitionRange(documents: TextDocuments, uri: string, position: Position): Location | undefined {
const compilation = accessCache(documents, uri);
const target = compilation.getTargetAt(position);
if (!target) {
return undefined;
}
const action = compilation.actions.get(target.name);
if (!action) {
return undefined;
}
return Location.create(uri, action.range);
}
}
private computeVariableDefinition(uri: string, dockerfile: Dockerfile, position: Position): Location | null {
const property = DockerDefinition.findDefinition(dockerfile, position);
return property ? Location.create(uri, property.getNameRange()) : null;
}
} else if (node["identifier"] && node["identifier"]['type'] == 'MemberExpression') {
let baseInfo = this.baseProcess(node["identifier"]);
functionSearchName = baseInfo.name;
functionName = 'function ' + functionSearchName + paramString;
if (type === travelMode.GET_DEFINE && searchRes === true) {
let bname = this.MemberExpressionFind(node["identifier"]);
if (bname.isInStat && bname.isInStat > 0) {
this.posSearchRet = this.createRetSymbol(bname.name, bname.isLocal);
return;
}
}
if (type === travelMode.FIND_REFS) {
if (functionSearchName == this.searchInfo.originalName){
let loc = node["identifier"]["loc"];
let nodeLoc1 = Location.create(this.docInfo["docUri"], loc);
this.refsLink.push(nodeLoc1);
}
}
if (type === travelMode.BUILD) {
let bname = this.baseProcess(node["identifier"]);
let originalName = bname.origion;
let loc = node['identifier']['loc'];
let rg = Location.create(this.docInfo["docUri"], Range.create(Position.create(loc["start"]["line"] - 1, loc["start"]["column"]), Position.create(loc["end"]["line"] - 1, loc["end"]["column"])));
let symbInfo = this.createSymbolInfo(functionName, functionSearchName, originalName, SymbolKind.Function, rg , bname.isLocal, prefix, deepLayer.concat(), paramArray);
newChunk = new Tools.chunkClass(functionSearchName, node.loc);
this.pushToChunkList(newChunk.chunkName, newChunk);
symbInfo.chunk = newChunk;
this.pushToAutoList(symbInfo);
//a:b , 隐式的self
private createLocationFromDefinition(
definitionNode: SyntaxNode | undefined,
uri: string,
): Location | undefined {
if (definitionNode) {
return Location.create(
uri,
Range.create(
Position.create(
definitionNode.startPosition.row,
definitionNode.startPosition.column,
),
Position.create(
definitionNode.endPosition.row,
definitionNode.endPosition.column,
),
),
);
}
}
}
export const createLocation = (uri: string, el: HasLocation): Location => {
return Location.create(uri, createRange(el));
};
vsDiag.relatedInformation = relatedInfo.map(info => {
return DiagnosticRelatedInformation.create(
Location.create(_convertPathToUri(info.filePath),
_convertRange(info.range)),
info.message
);
});
}