8000 IDE: Cleaner LSPTypechecker::retypecheck() interface. by jvilk-stripe · Pull Request #2304 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

IDE: Cleaner LSPTypechecker::retypecheck() interface. 8000 #2304

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

Merged
merged 3 commits into from
Dec 6, 2019
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
30 changes: 17 additions & 13 deletions main/lsp/LSPTypechecker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -456,21 +456,25 @@ LSPQueryResult LSPTypechecker::query(const core::lsp::Query &q, const std::vecto
return LSPQueryResult{move(out.second)};
}

TypecheckRun LSPTypechecker::retypecheck(LSPFileUpdates updates) const {
if (!updates.canTakeFastPath) {
Exception::raise("Tried to typecheck slow path updates with retypecheck. Retypecheck can only typecheck the "
"previously typechecked version of a file.");
}

for (const auto &file : updates.updatedFiles) {
auto path = file->path();
auto source = file->source();
auto fref = gs->findFileByPath(path);
if (!fref.exists() || fref.data(*gs).source() != source) {
Exception::raise("Retypecheck can only typecheck the previously typechecked version of a file.");
}
LSPFileUpdates LSPTypechecker::getNoopUpdate(std::vector<core::FileRef> frefs) const {
LSPFileUpdates noop;
noop.canTakeFastPath = true;
// Epoch isn't important for this update.
noop.versionStart = 0;
noop.versionEnd = 0;
for (auto fref : frefs) {
ENFORCE(fref.exists());
ENFORCE(fref.id() < indexed.size());
auto &index = indexed[fref.id()];
noop.updatedFileIndexes.push_back({index.tree->deepCopy(), index.file});
noop.updatedFiles.push_back(gs->getFiles()[fref.id()]);
noop.updatedFileHashes.push_back(globalStateHashes[fref.id()]);
}
return noop;
}

TypecheckRun LSPTypechecker::retypecheck(vector<core::FileRef> frefs) const {
LSPFileUpdates updates = getNoopUpdate(move(frefs));
return runTypechecking(move(updates));
}

Expand Down
11 changes: 8 additions & 3 deletions main/lsp/LSPTypechecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ class LSPTypechecker final {
* sending diagnostics to the editor. */
void commitTypecheckRun(TypecheckRun run);

/**
* Get an LSPFileUpdates containing the latest versions of the given files. It's a "no-op" file update because it
* doesn't actually change anything.
*/
LSPFileUpdates getNoopUpdate(std::vector<core::FileRef> frefs) const;

public:
LSPTypechecker(const std::shared_ptr<const LSPConfiguration> &config);
~LSPTypechecker() = default;
Expand All @@ -95,10 +101,9 @@ class LSPTypechecker final {
bool typecheck(LSPFileUpdates updates);

/**
* Re-typechecks the provided input to re-produce error messages. Input *must* match already committed state!
* Provided to facilitate code actions.
* Re-typechecks the provided files to re-produce error messages.
*/
TypecheckRun retypecheck(LSPFileUpdates updates) const;
TypecheckRun retypecheck(std::vector<core::FileRef> frefs) const;

/** Runs the provided query against the given files, and returns matches. */
LSPQueryResult query(const core::lsp::Query &q, const std::vector<core::FileRef> &filesForQuery) const;
Expand Down
9 changes: 1 addition & 8 deletions main/lsp/requests/code_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,8 @@ unique_ptr<ResponseMessage> LSPLoop::handleTextDocumentCodeAction(LSPTypechecker
return response;
}

LSPFileUpdates updates;
updates.canTakeFastPath = true;
const auto &globalStateHashes = typechecker.getFileHashes();
ENFORCE(file.id() < globalStateHashes.size());
updates.updatedFileHashes = {globalStateHashes[file.id()]};
updates.updatedFiles.push_back(make_shared<core::File>(string(file.data(gs).path()), string(file.data(gs).source()),
core::File::Type::Normal));
// Simply querying the file in question is insufficient since indexing errors would not be detected.
auto run = typechecker.retypecheck(move(updates));
auto run = typechecker.retypecheck({file});
auto loc = params.range->toLoc(gs, file);
for (auto &error : run.errors) {
if (!error->isSilenced && !error->autocorrects.empty()) {
Expand Down
0