Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/2023 01 20 #378

Merged
merged 5 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## 0.6.9 - 2023-01-20

### Added

- Natspec completions ([#342](https://github.com/NomicFoundation/hardhat-vscode/issues/342))([#343](https://github.com/NomicFoundation/hardhat-vscode/issues/343))([#296](https://github.com/NomicFoundation/hardhat-vscode/issues/296))
- Updated parser to support latest solidity syntax

### Fixed

- Improve forge binary lookup ([#354](https://github.com/NomicFoundation/hardhat-vscode/pull/354))
- Fix logic on checking workspace folder capability ([#375](https://github.com/NomicFoundation/hardhat-vscode/pull/375))

## 0.6.8 - 2023-01-16

### Added
Expand Down
6 changes: 6 additions & 0 deletions EXTENSION.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ Relative imports pull their suggestions from the file system based on the curren

![Import completions](https://raw.githubusercontent.com/NomicFoundation/hardhat-vscode/main/docs/gifs/import-completion.gif "Import completions")

Natspec documentation completion is also supported

![Natspec contract completions](https://raw.githubusercontent.com/NomicFoundation/hardhat-vscode/main/docs/gifs/natspec-contract.gif "Natspec contract completion")

![Natspec function completions](https://raw.githubusercontent.com/NomicFoundation/hardhat-vscode/main/docs/gifs/natspec-function.gif "Natspec function completion")

---

### Navigation
Expand Down
44 changes: 43 additions & 1 deletion client/src/formatter/forgeFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as vscode from "vscode";
import * as cp from "child_process";
import { runCmd, runningOnWindows } from "../utils/os";

export async function formatDocument(
document: vscode.TextDocument
Expand All @@ -11,13 +13,16 @@ export async function formatDocument(
lastLine.range.end
);

const forgeCommand = await resolveForgeCommand();

const formatted = await new Promise<string>((resolve, reject) => {
const currentDocument = vscode.window.activeTextEditor?.document.uri;
const rootPath = currentDocument
? vscode.workspace.getWorkspaceFolder(currentDocument)?.uri.fsPath
: undefined;

const forge = cp.execFile(
"forge",
forgeCommand,
["fmt", "--raw", "-"],
{ cwd: rootPath },
(err, stdout) => {
Expand All @@ -35,3 +40,40 @@ export async function formatDocument(

return [vscode.TextEdit.replace(fullTextRange, formatted)];
}

async function resolveForgeCommand() {
const potentialForgeCommands = ["forge"];

if (runningOnWindows()) {
potentialForgeCommands.push(
`${process.env.USERPROFILE}\\.cargo\\bin\\forge`
);
} else {
potentialForgeCommands.push(`${process.env.HOME}/.foundry/bin/forge`);
}

for (const potentialForgeCommand of potentialForgeCommands) {
try {
await runCmd(`${potentialForgeCommand} --version`);
return potentialForgeCommand;
} catch (error: any) {
if (
error.code === 127 || // unix
error.toString().includes("is not recognized") || // windows (code: 1)
error.toString().includes("cannot find the path") // windows (code: 1)
) {
// command not found, then try the next potential command
continue;
} else {
// command found but execution failed
throw error;
}
}
}

throw new Error(
`Couldn't find forge binary. Performed lookup: ${JSON.stringify(
potentialForgeCommands
)}`
);
}
18 changes: 18 additions & 0 deletions client/src/utils/os.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { exec } from "child_process";
import os from "os";

export async function runCmd(cmd: string, cwd?: string): Promise<string> {
return new Promise((resolve, reject) => {
exec(cmd, { cwd }, function (error, stdout) {
if (error !== null) {
reject(error);
}

resolve(stdout);
});
});
}

export function runningOnWindows() {
return os.platform() === "win32";
}
4 changes: 2 additions & 2 deletions coc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@ignored/coc-solidity",
"description": "Solidity and Hardhat support for coc.nvim",
"license": "MIT",
"version": "0.6.8",
"version": "0.6.9",
"author": "Nomic Foundation",
"repository": {
"type": "git",
Expand All @@ -28,7 +28,7 @@
"clean": "rimraf out .nyc_output coverage *.tsbuildinfo *.log"
},
"dependencies": {
"@ignored/solidity-language-server": "0.6.8"
"@ignored/solidity-language-server": "0.6.9"
},
"devDependencies": {
"@types/node": "^17.0.21",
Expand Down
Binary file added docs/gifs/natspec-contract.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/gifs/natspec-function.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"displayName": "Solidity",
"description": "Solidity and Hardhat support by the Hardhat team",
"license": "MIT",
"version": "0.6.8",
"version": "0.6.9",
"private": true,
"main": "./client/out/extension.js",
"module": "./client/out/extension.js",
Expand Down
4 changes: 2 additions & 2 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@ignored/solidity-language-server",
"description": "Solidity language server by Nomic Foundation",
"license": "MIT",
"version": "0.6.8",
"version": "0.6.9",
"author": "Nomic Foundation",
"repository": {
"type": "git",
Expand Down Expand Up @@ -69,7 +69,7 @@
"@nomicfoundation/solidity-analyzer": "0.1.0",
"@sentry/node": "6.19.1",
"@sentry/tracing": "6.19.1",
"@solidity-parser/parser": "^0.14.0",
"@solidity-parser/parser": "^0.14.5",
"c3-linearization": "0.3.0",
"fast-glob": "3.2.11",
"fs-extra": "^10.0.0",
Expand Down
53 changes: 44 additions & 9 deletions server/src/frameworks/Foundry/FoundryProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ export class FoundryProject extends Project {
}

public async initialize(): Promise<void> {
this.initializeError = undefined; // clear any potential error on restart

try {
const forgePath = runningOnWindows()
? "%USERPROFILE%\\.cargo\\bin\\forge"
: "~/.foundry/bin/forge";
const forgeCommand = await this._resolveForgeCommand();
const config = JSON.parse(
await runCmd(`${forgePath} config --json`, this.basePath)
await runCmd(`${forgeCommand} config --json`, this.basePath)
);
this.sourcesPath = path.join(this.basePath, config.src);
this.testsPath = path.join(this.basePath, config.test);
Expand All @@ -58,22 +58,21 @@ export class FoundryProject extends Project {
this.configSolcVersion = config.solc || undefined; // may come as null otherwise

const rawRemappings = await runCmd(
`${forgePath} remappings`,
`${forgeCommand} remappings`,
this.basePath
);
this.remappings = this._parseRemappings(rawRemappings);
} catch (error: any) {
this.serverState.logger.error(error.toString());

switch (error.code) {
case 127:
this.initializeError =
"Couldn't run `forge`. Please check that your foundry installation is correct.";
break;
case 134:
this.initializeError =
"Running `forge` failed. Please check that your foundry.toml file is correct.";
break;
case undefined:
this.initializeError = `${error}`;
break;
default:
this.initializeError = `Unexpected error while running \`forge\`: ${error}`;
}
Expand Down Expand Up @@ -216,4 +215,40 @@ export class FoundryProject extends Project {

return remappings;
}

// Returns the forge binary path
private async _resolveForgeCommand() {
const potentialForgeCommands = ["forge"];

if (runningOnWindows()) {
potentialForgeCommands.push("%USERPROFILE%\\.cargo\\bin\\forge");
} else {
potentialForgeCommands.push("~/.foundry/bin/forge");
}

for (const potentialForgeCommand of potentialForgeCommands) {
try {
await runCmd(`${potentialForgeCommand} --version`);
return potentialForgeCommand;
} catch (error: any) {
if (
error.code === 127 || // unix
error.toString().includes("is not recognized") || // windows (code: 1)
error.toString().includes("cannot find the path") // windows (code: 1)
) {
// command not found, then try the next potential command
continue;
} else {
// command found but execution failed
throw error;
}
}
}

throw new Error(
`Couldn't find forge binary. Performed lookup: ${JSON.stringify(
potentialForgeCommands
)}`
);
}
}
13 changes: 0 additions & 13 deletions server/src/parser/analyzer/matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import { AssemblyIfNode } from "@analyzer/nodes/AssemblyIfNode";
import { SubAssemblyNode } from "@analyzer/nodes/SubAssemblyNode";
import { NewExpressionNode } from "@analyzer/nodes/NewExpressionNode";
import { TupleExpressionNode } from "@analyzer/nodes/TupleExpressionNode";
import { TypeNameExpressionNode } from "@analyzer/nodes/TypeNameExpressionNode";
import { NameValueExpressionNode } from "@analyzer/nodes/NameValueExpressionNode";
import { NumberLiteralNode } from "@analyzer/nodes/NumberLiteralNode";
import { BooleanLiteralNode } from "@analyzer/nodes/BooleanLiteralNode";
Expand Down Expand Up @@ -588,18 +587,6 @@ export const find = matcher<Promise<Node>>({
documentsAnalyzer: SolFileIndexMap
) =>
new TupleExpressionNode(tupleExpression, uri, rootPath, documentsAnalyzer),
TypeNameExpression: async (
typeNameExpression: astTypes.TypeNameExpression,
uri: string,
rootPath: string,
documentsAnalyzer: SolFileIndexMap
) =>
new TypeNameExpressionNode(
typeNameExpression,
uri,
rootPath,
documentsAnalyzer
),
NameValueExpression: async (
nameValueExpression: astTypes.NameValueExpression,
uri: string,
Expand Down
32 changes: 0 additions & 32 deletions server/src/parser/analyzer/nodes/TypeNameExpressionNode.ts

This file was deleted.

7 changes: 5 additions & 2 deletions server/src/parser/analyzer/nodes/UsingForDeclarationNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ export class UsingForDeclarationNode extends Node {
uri,
rootPath,
documentsAnalyzer,
usingForDeclaration.libraryName
usingForDeclaration.libraryName ?? undefined
);
this.astNode = usingForDeclaration;

if (usingForDeclaration.loc && usingForDeclaration.libraryName) {
if (
usingForDeclaration.loc &&
usingForDeclaration.libraryName !== undefined
) {
this.nameLoc = {
start: {
line: usingForDeclaration.loc.start.line,
Expand Down
5 changes: 0 additions & 5 deletions server/src/parser/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ import type {
ThrowStatement,
TryStatement,
TupleExpression,
TypeNameExpression,
UnaryOperation,
UncheckedStatement,
UserDefinedTypeName,
Expand Down Expand Up @@ -175,7 +174,6 @@ export {
ThrowStatement,
TryStatement,
TupleExpression,
TypeNameExpression,
UnaryOperation,
UncheckedStatement,
UserDefinedTypeName,
Expand Down Expand Up @@ -248,8 +246,6 @@ export interface Searcher {
* @param uri Path to the file. Uri needs to be decoded and without the "file://" prefix.
* @param position Position in the file.
* @param from From which Node do we start searching.
* @param returnDefinitionNode If it is true, we will return the definition Node of found Node,
* otherwise we will return found Node. Default is true.
* @param searchInExpression If it is true, we will also look at the expressionNode for Node
* otherwise, we won't. Default is false.
* @returns Founded Node.
Expand Down Expand Up @@ -902,7 +898,6 @@ export const expressionNodeTypes = [
"NumberLiteral",
"Identifier",
"TupleExpression",
"TypeNameExpression",
];

/**
Expand Down
Loading