-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlsp_testing.diff
More file actions
227 lines (214 loc) · 7.63 KB
/
Copy pathlsp_testing.diff
File metadata and controls
227 lines (214 loc) · 7.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
diff --git a/libsolidity/lsp/LanguageServer.cpp b/libsolidity/lsp/LanguageServer.cpp
index 2b8b62706..905ea6b38 100644
--- a/libsolidity/lsp/LanguageServer.cpp
+++ b/libsolidity/lsp/LanguageServer.cpp
@@ -565,3 +565,44 @@ std::tuple<ASTNode const*, int> LanguageServer::astNodeAndOffsetAtSourceLocation
return {locateInnermostASTNode(*sourcePos, m_compilerStack.ast(_sourceUnitName)), *sourcePos};
}
+
+bool LanguageServer::readFromIO(std::string value){
+ /*
+ Read in the json file directly.
+ */
+ Json::Value jsonMessageParsed;
+ std::string jsonParsingErrors;
+ solidity::util::jsonParseStrict(value, jsonMessageParsed, &jsonParsingErrors);
+ if (!jsonParsingErrors.empty() || !jsonMessageParsed || !jsonMessageParsed.isObject())
+ {
+ lspDebug(fmt::format("failed to parse json"));
+ return false;
+ }
+
+ std::optional<Json::Value> const jsonMessage = {std::move(jsonMessageParsed)};
+ if (!jsonMessage){
+ lspDebug(fmt::format("failed to parse json"));
+ return false;
+ }
+
+ MessageID id;
+ if ((*jsonMessage)["method"].isString())
+ {
+ std::string const methodName = (*jsonMessage)["method"].asString();
+ id = (*jsonMessage)["id"];
+ printf("received method call: %s\n", methodName.c_str());
+
+ if (auto handler = util::valueOrDefault(m_handlers, methodName)){
+ handler(id, (*jsonMessage)["params"]);
+ printf("param handler\n");
+ }
+ else{
+ printf("unknown method call: %s\n", methodName.c_str());
+ }
+
+ } else {
+ lspDebug(fmt::format("failed error with getting method"));
+ }
+
+ return true;
+}
diff --git a/libsolidity/lsp/LanguageServer.h b/libsolidity/lsp/LanguageServer.h
index d80f8e879..f3a34d91f 100644
--- a/libsolidity/lsp/LanguageServer.h
+++ b/libsolidity/lsp/LanguageServer.h
@@ -80,6 +80,7 @@ public:
std::tuple<frontend::ASTNode const*, int> astNodeAndOffsetAtSourceLocation(std::string const& _sourceUnitName, langutil::LineColumn const& _filePos);
frontend::ASTNode const* astNodeAtSourceLocation(std::string const& _sourceUnitName, langutil::LineColumn const& _filePos);
frontend::CompilerStack const& compilerStack() const noexcept { return m_compilerStack; }
+ bool readFromIO(std::string value);
private:
/// Checks if the server is initialized (to be used by messages that need it to be initialized).
diff --git a/scripts/build.sh b/scripts/build.sh
index 6edd60bd9..9123c0d37 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -17,10 +17,10 @@ fi
mkdir -p "${BUILDDIR}"
cd "${BUILDDIR}"
-cmake .. -DCMAKE_BUILD_TYPE="$BUILD_TYPE" "${@:2}"
+cmake .. -DCMAKE_BUILD_TYPE="$BUILD_TYPE" -DUSE_Z3=OFF "${@:2}"
make -j2
-if [[ "${CI}" == "" ]]; then
- echo "Installing ..."
- sudo make install
-fi
+#if [[ "${CI}" == "" ]]; then
+# echo "Installing ..."
+# sudo make install
+#fi
diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp
index 4c08efb51..a2bfbe9c8 100644
--- a/solc/CommandLineInterface.cpp
+++ b/solc/CommandLineInterface.cpp
@@ -606,6 +606,7 @@ void CommandLineInterface::readInputFiles()
}
if (
+ m_options.input.mode != InputMode::LanguageIO &&
m_options.input.mode != InputMode::LanguageServer &&
m_fileReader.sourceUnits().empty() &&
!m_standardJsonInput.has_value()
@@ -675,7 +676,6 @@ bool CommandLineInterface::run(int _argc, char const* const* _argv)
{
if (!parseArguments(_argc, _argv))
return false;
-
readInputFiles();
processInput();
return true;
@@ -743,6 +743,14 @@ void CommandLineInterface::processInput()
case InputMode::Version:
printVersion();
break;
+ case InputMode::LanguageIO:{
+ // Currently we expect it to come from stdin, but should not be the case in the future.
+ std::string value = readUntilEnd(m_sin);
+ sout() << value << std::endl;
+
+ commandLineIO(value);
+ break;
+ }
case InputMode::StandardJson:
{
solAssert(m_standardJsonInput.has_value());
@@ -1075,6 +1083,19 @@ void CommandLineInterface::handleAst()
}
}
+void CommandLineInterface::commandLineIO(std::string m_standardJsonInput) {
+ sout() << "stdin ::" << std::endl << std::endl;
+ // transport is not needed
+// std::string m_standardJsonInput = util::readFileAsString("/standard_json_example.json"); // readUntilEnd(m_sin);
+ sout() << m_standardJsonInput << std::endl << std::endl;
+ sout() << "====" << std::endl << std::endl;
+
+ lsp::StdioTransport transport;
+ lsp::LanguageServer{transport}.readFromIO(m_standardJsonInput);
+ // exit nicely
+ exit(0);
+}
+
void CommandLineInterface::serveLSP()
{
lsp::StdioTransport transport;
diff --git a/solc/CommandLineInterface.h b/solc/CommandLineInterface.h
index 1fb4ac00b..567df1f60 100644
--- a/solc/CommandLineInterface.h
+++ b/solc/CommandLineInterface.h
@@ -89,6 +89,7 @@ private:
void assembleFromEVMAssemblyJSON();
void serveLSP();
void link();
+ void commandLineIO(std::string m_standardJsonInput);
void writeLinkedFiles();
/// @returns the ``// <identifier> -> name`` hint for library placeholders.
static std::string libraryPlaceholderHint(std::string const& _libraryName);
diff --git a/solc/CommandLineParser.cpp b/solc/CommandLineParser.cpp
index 6216af4a0..84f522d19 100644
--- a/solc/CommandLineParser.cpp
+++ b/solc/CommandLineParser.cpp
@@ -92,6 +92,7 @@ static std::string const g_strOverwrite = "overwrite";
static std::string const g_strRevertStrings = "revert-strings";
static std::string const g_strStopAfter = "stop-after";
static std::string const g_strParsing = "parsing";
+static std::string const g_strLSPIO = "lspio";
/// Possible arguments to for --revert-strings
static std::set<std::string> const g_revertStringsArgs
@@ -146,6 +147,7 @@ static std::map<InputMode, std::string> const g_inputModeName = {
{InputMode::Linker, "linker"},
{InputMode::LanguageServer, "language server (LSP)"},
{InputMode::EVMAssemblerJSON, "EVM assembler (JSON format)"},
+ {InputMode::LanguageIO, "language IO"},
};
void CommandLineParser::checkMutuallyExclusive(std::vector<std::string> const& _optionNames)
@@ -485,6 +487,7 @@ void CommandLineParser::parseOutputSelection()
case InputMode::Help:
case InputMode::License:
case InputMode::Version:
+ case InputMode::LanguageIO:
case InputMode::LanguageServer:
solAssert(false);
case InputMode::Compiler:
@@ -686,6 +689,10 @@ General Information)").c_str(),
"Switch to language server mode (\"LSP\"). Allows the compiler to be used as an analysis backend "
"for your favourite IDE."
)
+ (
+ g_strLSPIO.c_str(),
+ "langauge server io"
+ )
;
desc.add(alternativeInputModes);
@@ -958,6 +965,7 @@ void CommandLineParser::processArgs()
g_strImportAst,
g_strLSP,
g_strImportEvmAssemblerJson,
+ g_strLSPIO,
});
if (m_args.count(g_strHelp) > 0)
@@ -968,6 +976,8 @@ void CommandLineParser::processArgs()
m_options.input.mode = InputMode::Version;
else if (m_args.count(g_strStandardJSON) > 0)
m_options.input.mode = InputMode::StandardJson;
+ else if (m_args.count(g_strLSPIO))
+ m_options.input.mode = InputMode::LanguageIO;
else if (m_args.count(g_strLSP))
m_options.input.mode = InputMode::LanguageServer;
else if (m_args.count(g_strAssemble) > 0 || m_args.count(g_strStrictAssembly) > 0 || m_args.count(g_strYul) > 0)
@@ -1029,6 +1039,8 @@ void CommandLineParser::processArgs()
if (m_options.input.mode == InputMode::LanguageServer)
return;
+ else if (m_args.count(g_strLSPIO))
+ return;
checkMutuallyExclusive({g_strColor, g_strNoColor});
checkMutuallyExclusive({g_strStopAfter, g_strGas});
diff --git a/solc/CommandLineParser.h b/solc/CommandLineParser.h
index b95973562..713a2307d 100644
--- a/solc/CommandLineParser.h
+++ b/solc/CommandLineParser.h
@@ -57,7 +57,8 @@ enum class InputMode
Linker,
Assembler,
LanguageServer,
- EVMAssemblerJSON
+ EVMAssemblerJSON,
+ LanguageIO
};
struct CompilerOutputs