-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Against each solidity file, we show a language status item that displays the `hardhat.config.{ts/js}` file that is being used for validation. If there is no hardhat project we show a warning message. Fixes #56.
- Loading branch information
Showing
16 changed files
with
259 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { languages, Uri, LanguageStatusSeverity, TextEditor } from "vscode"; | ||
import { RequestType } from "vscode-languageclient/node"; | ||
import { ExtensionState } from "../types"; | ||
|
||
type GetSolFileDetailsParams = { uri: Uri }; | ||
type GetSolFileDetailsResponse = | ||
| { found: false } | ||
| { found: true; hardhat: false } | ||
| { | ||
found: true; | ||
hardhat: true; | ||
configPath: string; | ||
configDisplayPath: string; | ||
}; | ||
|
||
const GetSolFileDetails = new RequestType< | ||
GetSolFileDetailsParams, | ||
GetSolFileDetailsResponse, | ||
void | ||
>("solidity/getSolFileDetails"); | ||
|
||
export function updateHardhatProjectLanguageItem( | ||
extensionState: ExtensionState | ||
) { | ||
return async (e: TextEditor) => { | ||
if (e.document.languageId !== "solidity") { | ||
return clearHardhatConfigState(extensionState); | ||
} | ||
|
||
const params: GetSolFileDetailsParams = { uri: e.document.uri }; | ||
const response = await extensionState.client.sendRequest( | ||
GetSolFileDetails, | ||
params | ||
); | ||
|
||
if (!response.found) { | ||
return clearHardhatConfigState(extensionState); | ||
} | ||
|
||
if (extensionState.hardhatConfigStatusItem === null) { | ||
const statusItem = languages.createLanguageStatusItem( | ||
"hardhat-config-file", | ||
{ | ||
language: "solidity", | ||
} | ||
); | ||
|
||
extensionState.hardhatConfigStatusItem = statusItem; | ||
} | ||
|
||
if (response.found && !response.hardhat) { | ||
extensionState.hardhatConfigStatusItem.severity = | ||
LanguageStatusSeverity.Warning; | ||
extensionState.hardhatConfigStatusItem.text = | ||
"Not part of a Hardhat project"; | ||
|
||
extensionState.hardhatConfigStatusItem.command = null; | ||
|
||
return; | ||
} | ||
|
||
if (response.found && response.hardhat) { | ||
extensionState.hardhatConfigStatusItem.text = response.configDisplayPath; | ||
extensionState.hardhatConfigStatusItem.command = { | ||
title: "Open config file", | ||
command: "vscode.open", | ||
arguments: [response.configPath], | ||
}; | ||
|
||
return; | ||
} | ||
|
||
return clearHardhatConfigState(extensionState); | ||
}; | ||
} | ||
|
||
function clearHardhatConfigState(extensionState: ExtensionState): void { | ||
if (extensionState.hardhatConfigStatusItem === null) { | ||
return; | ||
} | ||
|
||
extensionState.hardhatConfigStatusItem.dispose(); | ||
extensionState.hardhatConfigStatusItem = null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.