Skip to content

Commit

Permalink
feat: use path Symbol to support more file navigations
Browse files Browse the repository at this point in the history
  • Loading branch information
AnWeber committed Jan 14, 2024
1 parent 645a324 commit 37f816c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 39 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## [unreleased]
## [6.11.2] (2023-01-14)

### Feature
- add navigation support to imported files (#250)

### Fix
- Intellij store variables independent from current env in global cache (Anweber/httpyac#612)
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"publisher": "anweber",
"description": "Quickly and easily send REST, Soap, GraphQL, GRPC, MQTT, RabbitMQ and WebSocket requests directly within Visual Studio Code",
"version": "6.11.1",
"version": "6.11.2",
"homepage": "https://github.com/AnWeber/vscode-httpyac",
"repository": {
"type": "git",
Expand Down Expand Up @@ -1544,7 +1544,7 @@
"dependencies": {
"filesize": "^10.1.0",
"httpsnippet": "^3.0.1",
"httpyac": "^6.11.0",
"httpyac": "^6.11.1",
"lodash": "^4.17.21",
"mime-types": "^2.1.35",
"uuid": "^9.0.1"
Expand Down
54 changes: 24 additions & 30 deletions src/provider/httpDefinitionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,46 @@ import * as vscode from 'vscode';
import * as httpyac from 'httpyac';
import { DocumentStore } from '../documentStore';

import * as path from 'path';



export class HttpDefinitionProvider implements vscode.DefinitionProvider {
constructor(readonly documentStore: DocumentStore) {
}
constructor(readonly documentStore: DocumentStore) {}

public async provideDefinition(
document: vscode.TextDocument,
position: vscode.Position
): Promise<vscode.Definition | vscode.LocationLink[]> {

const result: Array<vscode.Location> = [];
const httpFile = await this.documentStore.getHttpFile(document);
const workingDir = path.dirname(document.fileName);
const word = document.getText(document.getWordRangeAtPosition(position));
const line = document.lineAt(position);

if(httpFile){
if (httpFile) {
for (const httpRegion of httpFile.httpRegions) {
// find if current position is with in requestBody
const requestBody =
httpRegion.symbol.children?.find(obj =>
// this could be with new new SymbolKind.File
obj.kind === httpyac.HttpSymbolKind.requestBody &&
obj.startLine === line.lineNumber
const pathSymbols = httpRegion.symbol
.getSymbolsForLine(position.line)
.filter(
symbol =>
symbol.kind === httpyac.HttpSymbolKind.path &&
symbol.startOffset <= position.character &&
position.character <= symbol.endOffset
);

for (const pathSymbol of pathSymbols) {
const path = await httpyac.utils.toAbsoluteFilename(
pathSymbol.description,
httpyac.io.fileProvider.dirname(httpFile.fileName)
);
if(requestBody){
// check if request body is link to file
const source = requestBody.source;
const reStr = `^<@?\\w*\\s+(.*?${word}.*?)\\s*$`;
const match = source?.match(reStr);
if (match) {
const potentialFname = match[1] || match[2];
// resolve from relative path to absolute
const fullPath = path.resolve(workingDir, potentialFname);
if (path instanceof vscode.Uri) {
result.push(
new vscode.Location(vscode.Uri.file(fullPath), new vscode.Position(0, 1))
new vscode.Location(
path,
new vscode.Range(
new vscode.Position(pathSymbol.startLine, pathSymbol.startOffset),
new vscode.Position(pathSymbol.endLine, pathSymbol.endOffset)
)
)
);
}
break;
}
}
}
return Promise.resolve(result);
return result;
}

}
2 changes: 2 additions & 0 deletions src/provider/httpDocumentSymbolProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export class HttpDocumentSymbolProvider implements vscode.DocumentSymbolProvider
return vscode.SymbolKind.String;
case HttpSymbolKind.response:
return vscode.SymbolKind.Package;
case HttpSymbolKind.path:
return vscode.SymbolKind.File;
default:
return vscode.SymbolKind.Object;
}
Expand Down

0 comments on commit 37f816c

Please sign in to comment.