LSP: Implements goto-definition.

This commit is contained in:
Christian Parpart
2022-03-14 11:59:41 +01:00
parent 1035eacb53
commit 2b2f8acc12
16 changed files with 719 additions and 91 deletions
+68
View File
@@ -0,0 +1,68 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
import "./lib.sol";
interface I
{
function f(uint x) external returns (uint);
}
contract IA is I
{
function f(uint x) public pure override returns (uint) { return x + 1; }
}
contract IB is I
{
function f(uint x) public pure override returns (uint) { return x + 2; }
}
library IntLib
{
function add(int self, int b) public pure returns (int) { return self + b; }
}
contract C
{
I obj;
function virtual_inheritance() public payable
{
obj = new IA();
obj.f(1); // goto-definition should jump to definition of interface.
}
using IntLib for *;
function using_for(int i) pure public
{
i.add(5);
14.add(4);
}
function useLib(uint n) public payable returns (uint)
{
return Lib.add(n, 1);
}
function enums(Color c) public pure returns (Color d)
{
Color e = Color.Red;
if (c == e)
d = Color.Green;
else
d = c;
}
type Price is uint128;
function udlTest() public pure returns (uint128)
{
Price p = Price.wrap(128);
return Price.unwrap(p);
}
function structCtorTest(uint8 v) public pure returns (uint8 result)
{
RGBColor memory c = RGBColor(v, 2 * v, 3 * v);
result = c.red;
}
}
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
import {Weather as Wetter} from "./lib.sol";
import "./lib.sol" as That;
contract C
{
function test_symbol_alias() public pure returns (Wetter result)
{
result = Wetter.Sunny;
}
function test_library_alias() public pure returns (That.Color result)
{
That.Color color = That.Color.Red;
result = color;
}
}
+26
View File
@@ -1,6 +1,25 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.0;
/// Some Error type E.
error E(uint, uint);
enum Weather {
Sunny,
Cloudy,
Rainy
}
/// Some custom Color enum type holding 3 colors.
enum Color {
/// Red color.
Red,
/// Green color.
Green,
/// Blue color.
Blue
}
library Lib
{
function add(uint a, uint b) public pure returns (uint result)
@@ -13,3 +32,10 @@ library Lib
uint unused;
}
}
struct RGBColor
{
uint8 red;
uint8 green;
uint8 blue;
}