Skip to content

Commit

Permalink
feat: some improvements for path symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
AnWeber committed Jan 14, 2024
1 parent 7f8803c commit 4a976c3
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 34 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## [unreleased]
## [6.11.1] (2023-01-14)

### Fix
- Intellij store variables independent from current env in global cache (#612)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"publisher": "AnWeber",
"description": "HTTP/REST CLI Client for *.http files",
"version": "6.11.0",
"version": "6.11.1",
"homepage": "https://github.com/AnWeber/httpyac",
"repository": {
"type": "git",
Expand Down
14 changes: 14 additions & 0 deletions src/models/httpSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ export class HttpSymbol {
this.source = options.source;
}

public getSymbolsForLine(line: number): Array<HttpSymbol> {
const result: Array<HttpSymbol> = [];
if (this.startLine <= line || this.endLine >= line) {
result.push(this);
if (this.children) {
for (const child of this.children) {
result.push(...child.getSymbolsForLine(line));
}
}
}

return result;
}

public filter(predicate: (symbol: HttpSymbol) => boolean): Array<HttpSymbol> {
const result: Array<HttpSymbol> = [];
if (this.children) {
Expand Down
11 changes: 11 additions & 0 deletions src/plugins/core/parse/outputRedirectionHttpRegionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ export async function parseOutputRedirection(
startOffset: 0,
endLine: next.value.line,
endOffset: next.value.textLine.length,
children: [
new models.HttpSymbol({
name: 'filename',
description: fileName,
kind: models.HttpSymbolKind.path,
startLine: next.value.line,
startOffset: next.value.textLine.indexOf(fileName),
endLine: next.value.line,
endOffset: next.value.textLine.indexOf(fileName) + fileName.length,
}),
],
}),
],
};
Expand Down
23 changes: 18 additions & 5 deletions src/plugins/core/parse/requestBodyHttpRegionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export async function parseRequestBody(
const next = lineReader.next();
if (!next.done) {
if (requestBody.rawBody.length > 0 || !utils.isStringEmpty(next.value.textLine)) {
requestBody.rawBody.push(parseLine(next.value.textLine));
const symbols: Array<models.HttpSymbol> = [];

if (!requestBody.symbol || requestBody.symbol.endLine !== next.value.line - 1) {
Expand All @@ -33,6 +32,24 @@ export async function parseRequestBody(
requestBody.symbol.children?.push?.(...utils.parseHandlebarsSymbols(next.value.textLine, next.value.line));
}

const fileImport = utils.parseFileImport(next.value.textLine);
if (fileImport) {
requestBody.rawBody.push(fileImport);
requestBody.symbol.children?.push(
new models.HttpSymbol({
name: 'filename',
description: fileImport.fileName,
kind: models.HttpSymbolKind.path,
startLine: next.value.line,
startOffset: next.value.textLine.indexOf(fileImport.fileName),
endLine: next.value.line,
endOffset: next.value.textLine.indexOf(fileImport.fileName) + fileImport.fileName.length,
})
);
} else {
requestBody.rawBody.push(next.value.textLine);
}

return {
nextParserLine: next.value.line,
symbols,
Expand All @@ -53,7 +70,3 @@ export function getRequestBody(context: models.ParserContext) {
}
return result;
}

function parseLine(textLine: string) {
return utils.parseFileImport(textLine) || textLine;
}
14 changes: 13 additions & 1 deletion src/plugins/core/parse/responseRefHttpRegionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export async function parseResponseRef(
httpRegion.responseRefs = [];
}

httpRegion.responseRefs.push(match.groups.fileName);
const filename = match.groups.fileName;
httpRegion.responseRefs.push(filename);
return {
nextParserLine: next.value.line,
symbols: [
Expand All @@ -34,6 +35,17 @@ export async function parseResponseRef(
startOffset: 0,
endLine: next.value.line,
endOffset: next.value.textLine.length,
children: [
new HttpSymbol({
name: 'filename',
description: filename,
kind: HttpSymbolKind.path,
startLine: next.value.line,
startOffset: textLine.indexOf(filename),
endLine: next.value.line,
endOffset: textLine.indexOf(filename) + filename.length,
}),
],
}),
],
};
Expand Down
61 changes: 39 additions & 22 deletions src/plugins/graphql/gqlHttpRegionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,8 @@ export async function parseGraphql(
gqlData.fragments[gqlContent.name] = gqlContent.gql;
}
return {
nextParserLine: gqlContent.endLine,
symbols: [
new models.HttpSymbol({
name: 'gql',
description: 'gql',
kind: models.HttpSymbolKind.gql,
startLine: gqlContent.startLine,
startOffset: 0,
endLine: gqlContent.endLine,
endOffset: gqlContent.endOffset,
}),
],
nextParserLine: gqlContent.symbol.endLine,
symbols: [gqlContent.symbol],
};
}
return false;
Expand Down Expand Up @@ -80,9 +70,26 @@ async function getGQLContent(lineReader: models.HttpLineGenerator): Promise<GqlP
if (fileMatches && fileMatches.groups?.fileName) {
const parserPath = fileMatches.groups.fileName.trim();
return {
startLine,
endLine: startLine,
endOffset: next.value.textLine.length,
symbol: new models.HttpSymbol({
name: 'gql',
description: 'gql',
kind: models.HttpSymbolKind.gql,
startLine,
startOffset: 0,
endLine: startLine,
endOffset: next.value.textLine.length,
children: [
new models.HttpSymbol({
name: 'filename',
description: parserPath,
kind: models.HttpSymbolKind.path,
startLine: next.value.line,
startOffset: next.value.textLine.indexOf(parserPath),
endLine: next.value.line,
endOffset: next.value.textLine.indexOf(parserPath) + parserPath.length,
}),
],
}),
name: fileMatches.groups.name || fileMatches.groups.fileName,
gql: (context: models.ProcessorContext) =>
utils.replaceFilePath(parserPath, context, (path: models.PathLike) => fileProvider.readFile(path, 'utf-8')),
Expand Down Expand Up @@ -119,8 +126,14 @@ function matchGqlContent(
if (EmptyLine.test(next.value.textLine)) {
return {
name,
startLine: value.line,
...prevReader,
symbol: new models.HttpSymbol({
name: 'gql',
description: 'gql',
kind: models.HttpSymbolKind.gql,
startLine: value.line,
startOffset: 0,
...prevReader,
}),
gql: utils.toMultiLineString(gqlLines),
};
}
Expand All @@ -130,16 +143,20 @@ function matchGqlContent(
}
return {
name,
startLine: value.line,
...prevReader,
symbol: new models.HttpSymbol({
name: 'gql',
description: 'gql',
kind: models.HttpSymbolKind.gql,
startLine: value.line,
startOffset: 0,
...prevReader,
}),
gql: utils.toMultiLineString(gqlLines),
};
}

export interface GqlParserResult {
name?: string;
startLine: number;
endLine: number;
endOffset: number;
symbol: models.HttpSymbol;
gql: string | ((context: models.ProcessorContext) => Promise<string | undefined>);
}
14 changes: 13 additions & 1 deletion src/plugins/grpc/protoHttpRegionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export async function parseProtoImport(
const matchProto = ProtoImport.exec(next.value.textLine);

if (matchProto?.groups?.fileName) {
const protoDefinition = new models.ProtoDefinition(matchProto.groups.fileName.trim());
const filename = matchProto?.groups?.fileName;
const protoDefinition = new models.ProtoDefinition(filename.trim());
protoDefinition.loaderOptions = {};

const protoSymbol: models.HttpSymbol = new models.HttpSymbol({
Expand All @@ -29,6 +30,17 @@ export async function parseProtoImport(
startOffset: 0,
endLine: next.value.line,
endOffset: next.value.textLine.length,
children: [
new models.HttpSymbol({
name: 'filename',
description: filename,
kind: models.HttpSymbolKind.path,
startLine: next.value.line,
startOffset: next.value.textLine.indexOf(filename),
endLine: next.value.line,
endOffset: next.value.textLine.indexOf(filename) + filename.length,
}),
],
});
const symbols = [protoSymbol];

Expand Down
16 changes: 15 additions & 1 deletion src/plugins/intellij/intellijHttpRegionParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface IntelliJParserResult {
endOffset: number;
data: models.ScriptData | IntellijScriptData;
isBeforeRequest: boolean;
symbols?: Array<models.HttpSymbol>;
}

export async function parseIntellijScript(
Expand Down Expand Up @@ -38,6 +39,7 @@ export async function parseIntellijScript(
startOffset: 0,
endLine: intellijContent.endLine,
endOffset: intellijContent.endOffset,
children: intellijContent.symbols,
}),
],
};
Expand All @@ -55,14 +57,26 @@ function getIntellijContent(lineReader: models.HttpLineGenerator, hasRequest: bo
if (fileMatches.groups.event === '<' && hasRequest) {
return false;
}
const fileName = fileMatches.groups.fileName.trim();
return {
startLine,
endLine: startLine,
endOffset: next.value.textLine.length,
data: {
fileName: fileMatches.groups.fileName.trim(),
fileName,
},
isBeforeRequest: fileMatches.groups.event === '<',
symbols: [
new models.HttpSymbol({
name: 'filename',
description: fileName,
kind: models.HttpSymbolKind.path,
startLine: next.value.line,
startOffset: next.value.textLine.indexOf(fileName),
endLine: next.value.line,
endOffset: next.value.textLine.indexOf(fileName) + fileName.length,
}),
],
};
}

Expand Down

0 comments on commit 4a976c3

Please sign in to comment.