Skip to content

Commit

Permalink
Enhance content resolution by introducing ResolveResult type and upda…
Browse files Browse the repository at this point in the history
…ting related methods
  • Loading branch information
cedric05 committed Jan 3, 2025
1 parent be9f841 commit af63d0e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
## Known issues
- notebook search with `m` or `y` in key won't work, as vscode configured default shortcut `m` to change cell to markdown and is annoying. [remove](https://code.visualstudio.com/docs/getstarted/keybindings#_keyboard-shortcuts-editor) `m` and `y` shortcuts for clean experience.

## 1.0.44:
- Update `dotextensions-build` to version 0.0.44a10
- Enhance content resolution by including resolved property

## 1.0.43
- Update `dotextensions-build` to version 0.0.44.a9
- **Feat** Fixes loading properties from property file on hover over url/json dict
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 @@ -2,7 +2,7 @@
"name": "dothttp-code",
"displayName": "Dothttp",
"description": "A Http Client for sending to and receiving from http endpoints (dothttp)",
"version": "1.0.43",
"version": "1.0.44",
"license": "Apache-2.0",
"publisher": "shivaprasanth",
"repository": {
Expand Down
28 changes: 22 additions & 6 deletions src/extension/native/services/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DothttpExecuteResponse } from '../../../common/response';
import { DothttpRunOptions } from '../../web/types/misc';
import { HttpFileTargetsDef } from '../../web/types/lang-parse';
import { ICommandClient, RunType, DotTttpSymbol, TypeResult, ImportHarResult } from '../../web/types/types';
import { ICommandClient, RunType, DotTttpSymbol, TypeResult, ImportHarResult, ResolveResult } from '../../web/types/types';
import * as vscode from 'vscode';
var mime = require('mime-types');

Expand All @@ -20,6 +20,7 @@ export class ClientHandler {
static GET_HAR_FORMAT_COMMAND = "/file/parse";
static CONTENT_TYPE_COMMAND = "/content/type";
static CONTENT_RESOLVE_COMMAND = "/content/resolve";
static FILE_RESOLVE_COMMAND = "/file/resolve";
static HAR_IMPORT_COMMAND = "/export/har2http";
static POSTMAN_EXPORT_COMMAND = "/export/http2postman";

Expand Down Expand Up @@ -110,19 +111,34 @@ export class ClientHandler {
}) as TypeResult;
}

async resolveContentFromContentPosition(position: number, content: string | null, contexts: string[], propertyFile: string | null, env: string[], properties: { [prop: string]: string }, filename: string | null, source?: string): Promise<TypeResult> {
async resolveContentFromContentPosition(
position: number,
filename: string | null,
content: string | null,
contexts: string[],
propertyFile: string | null,
env: string[],
properties: { [prop: string]: string },
source?: string): Promise<ResolveResult> {
return await this.cli?.request(ClientHandler.CONTENT_RESOLVE_COMMAND, {
content, position: position, source, env, properties,
file: filename,
contexts,
'property-file': propertyFile
}) as TypeResult;
}) as ResolveResult;
}

async resolveContentFromFilePosition(position: number, filename: string | null, env: string[], properties?: { [prop: string]: string }, source?: string): Promise<TypeResult> {
async resolveContentFromFilePosition(
position: number,
filename: string | null,
propertyFile: string | null,
env: string[],
properties?: { [prop: string]: string },
source?: string): Promise<ResolveResult> {
return await this.cli?.request(ClientHandler.CONTENT_RESOLVE_COMMAND, {
file: filename, position: position, source, env, properties
}) as TypeResult;
file: filename, position: position, source, env, properties,
'property-file': propertyFile
}) as ResolveResult;
}


Expand Down
23 changes: 17 additions & 6 deletions src/extension/native/services/editorIntellisense.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import { EndOfLine, Range, SymbolInformation, Command } from 'vscode';
import { ClientHandler } from "./client";
import { DotTttpSymbol } from "../../web/types/types";
import { DotTttpSymbol, ResolveResult } from "../../web/types/types";
import * as json from 'jsonc-parser';
import { parseURL } from 'whatwg-url';
import { parse as parseQueryString } from 'querystring';
Expand Down Expand Up @@ -131,22 +131,22 @@ class TypeResultMixin {
}
}

public async resolveType(document: vscode.TextDocument, position: vscode.Position) {
public async resolveType(document: vscode.TextDocument, position: vscode.Position): Promise<ResolveResult> {
const isNotebook = document.uri.scheme === Constants.notebookscheme;
const offset = document.offsetAt(position);
const env = this.fileStateService.getEnv(document.uri);
const properties: { [prop: string]: string } = {}
this.fileStateService.getProperties(document.uri).filter(prop => prop.enabled).map(prop => { properties[prop.key] = prop.value });
const propertyFile = this.fileStateService.getEnvFile()?.fsPath ?? null;
if (isNotebook) {
const notebookDoc = vscode.window.activeNotebookEditor;
if (notebookDoc?.notebook.uri.fsPath !== document.uri.fsPath) {
throw new Error("notebook uri mismatch");
}
const contexts = notebookDoc.notebook.getCells().map(cell => cell.document.getText());
const propertyFile = this.fileStateService.getEnvFile()?.fsPath ?? null;
return this.clientHandler.resolveContentFromContentPosition(offset, document.getText(), contexts, propertyFile, env, properties, document.uri.fsPath, "hover")
return this.clientHandler.resolveContentFromContentPosition(offset, document.uri.fsPath, document.getText(), contexts, propertyFile, env, properties, "hover")
} else {
return this.clientHandler.resolveContentFromFilePosition(offset, document.fileName, env, properties, "hover");
return this.clientHandler.resolveContentFromFilePosition(offset, document.fileName, propertyFile, env, properties, "hover");
}
}
}
Expand Down Expand Up @@ -199,9 +199,20 @@ export class DothttpClickDefinitionProvider extends TypeResultMixin implements v
hover_text = result.resolved;
}
}
var resolved_property = "";
if (result.property_at_pos) {
resolved_property =
`## Resolved Properties \`${result.property_at_pos.name}\`
\`\`\`jsonc
${JSON.stringify(result.property_at_pos.value, null, 2)}
\`\`\`
\n\n\n\n\n`;
}
var ret;
if (hover_text) {
ret = new vscode.MarkdownString(`## Resolved
ret = new vscode.MarkdownString(
`${resolved_property}
## After Replacing Properties
\`\`\`json
${hover_text}
\`\`\`
Expand Down
14 changes: 14 additions & 0 deletions src/extension/web/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,21 @@ export interface TypeResult {
"filename": string | null;
"name": string | null;
"value": any;
}

export interface ResolveResult {
"type": DothttpTypes;
"target": string | null;
"target_base": string | null;
"base_start": number | null;
"filename": string | null;
"name": string | null;
"value": any;
"resolved": any;
"property_at_pos":{
name: string;
value: any;
}
}

export enum RunType {
Expand Down

0 comments on commit af63d0e

Please sign in to comment.