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

fix(exthost/#3009): Call '$release*' APIs to clean-up extension host cache #3016

Merged
merged 6 commits into from
Jan 20, 2021
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
1 change: 1 addition & 0 deletions CHANGES_CURRENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- #3008 - SCM: Fix index-out-of-bound exception when rendering diff markers
- #3007 - Extensions: Show 'missing dependency' activation error to user
- #3011 - Vim: Visual Block - Handle 'I' and 'A' in visual block mode (fixes #1633)
- #3016 - Extensions: Fix memory leak in extension host language features (fixes #3009)

### Performance

Expand Down
23 changes: 20 additions & 3 deletions src/Exthost/CodeLens.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[@deriving show]
type t = {
type lens = {
cacheId: option(list(int)),
range: OneBasedRange.t,
command: option(Command.t),
Expand Down Expand Up @@ -33,12 +33,29 @@ let decode = Decode.decode;
let encode = Encode.encode;

module List = {
[@deriving show]
type cacheId = int;

[@deriving show]
type t = {
cacheId: option(cacheId),
lenses: list(lens),
};

let default = {cacheId: None, lenses: []};

module Decode = {
open Oni_Core.Json.Decode;

let simple = list(decode);
let simple = list(decode) |> map(lenses => {cacheId: None, lenses});

let nested = field("lenses", simple);
let nested =
obj(({field, _}) =>
{
lenses: field.required("lenses", list(decode)),
cacheId: field.optional("cacheId", int),
}
);

let decode = one_of([("nested", nested), ("simple", simple)]);
};
Expand Down
43 changes: 34 additions & 9 deletions src/Exthost/Exthost.rei
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,26 @@ module OneBasedRange: {

module CodeLens: {
[@deriving show]
type t = {
type lens = {
cacheId: option(list(int)),
range: OneBasedRange.t,
command: option(Command.t),
};

let decode: Json.decoder(t);
module List: {
[@deriving show]
type cacheId;

module List: {let decode: Json.decoder(list(t));};
[@deriving show]
type t = {
cacheId: option(cacheId),
lenses: list(lens),
};

let default: t;

let decode: Json.decoder(t);
};
};

module Location: {
Expand Down Expand Up @@ -593,9 +604,11 @@ module SignatureHelp: {
let decode: Json.decoder(t);
};

type cacheId;

module Response: {
type t = {
id: int,
cacheId,
signatures: list(Signature.t),
activeSignature: int,
activeParameter: int,
Expand All @@ -606,10 +619,15 @@ module SignatureHelp: {
};

module SuggestResult: {
[@deriving show];

type cacheId;

[@deriving show]
type t = {
completions: list(SuggestItem.t),
isIncomplete: bool,
cacheId: option(cacheId),
};

let empty: t;
Expand Down Expand Up @@ -1758,11 +1776,14 @@ module Request: {
module LanguageFeatures: {
let provideCodeLenses:
(~handle: int, ~resource: Uri.t, Client.t) =>
Lwt.t(option(list(CodeLens.t)));
Lwt.t(option(CodeLens.List.t));

let resolveCodeLens:
(~handle: int, ~codeLens: CodeLens.t, Client.t) =>
Lwt.t(option(CodeLens.t));
(~handle: int, ~codeLens: CodeLens.lens, Client.t) =>
Lwt.t(option(CodeLens.lens));

let releaseCodeLenses:
(~handle: int, ~cacheId: CodeLens.List.cacheId, Client.t) => unit;

let provideCompletionItems:
(
Expand All @@ -1778,6 +1799,9 @@ module Request: {
(~handle: int, ~chainedCacheId: ChainedCacheId.t, Client.t) =>
Lwt.t(SuggestItem.t);

let releaseCompletionItems:
(~handle: int, ~cacheId: SuggestResult.cacheId, Client.t) => unit;

let provideDocumentHighlights:
(
~handle: int,
Expand Down Expand Up @@ -1875,6 +1899,9 @@ module Request: {
) =>
Lwt.t(option(SignatureHelp.Response.t));

let releaseSignatureHelp:
(~handle: int, ~cacheId: SignatureHelp.cacheId, Client.t) => unit;

let provideDocumentFormattingEdits:
(
~handle: int,
Expand Down Expand Up @@ -1904,8 +1931,6 @@ module Request: {
Client.t
) =>
Lwt.t(option(list(Edit.SingleEditOperation.t)));

let releaseSignatureHelp: (~handle: int, ~id: int, Client.t) => unit;
};

module SCM: {
Expand Down
27 changes: 24 additions & 3 deletions src/Exthost/Request.re
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ module LanguageFeatures = {
);
};

let resolveCodeLens = (~handle: int, ~codeLens: CodeLens.t, client) => {
let resolveCodeLens = (~handle: int, ~codeLens: CodeLens.lens, client) => {
let decoder = Json.Decode.(nullable(CodeLens.decode));
Client.request(
~decoder,
Expand All @@ -266,6 +266,17 @@ module LanguageFeatures = {
client,
);
};

let releaseCodeLenses = (~handle: int, ~cacheId, client) => {
Client.notify(
~usesCancellationToken=false,
~rpcName="ExtHostLanguageFeatures",
~method="$releaseCodeLenses",
~args=`List([`Int(handle), `Int(cacheId)]),
client,
);
};

let provideCompletionItems =
(
~handle: int,
Expand Down Expand Up @@ -319,6 +330,16 @@ module LanguageFeatures = {
);
};

let releaseCompletionItems = (~handle: int, ~cacheId, client) => {
Client.notify(
~usesCancellationToken=false,
~rpcName="ExtHostLanguageFeatures",
~method="$releaseCompletionItems",
~args=`List([`Int(handle), `Int(cacheId)]),
client,
);
};

module Internal = {
let provideDefinitionLink =
(~handle, ~resource, ~position, method, client) => {
Expand Down Expand Up @@ -448,15 +469,15 @@ module LanguageFeatures = {
);
};

let releaseSignatureHelp = (~handle, ~id, client) =>
let releaseSignatureHelp = (~handle, ~cacheId, client) =>
Client.notify(
~rpcName="ExtHostLanguageFeatures",
~method="$releaseSignatureHelp",
~args=
`List(
Json.Encode.[
handle |> encode_value(int),
id |> encode_value(int),
cacheId |> encode_value(int),
],
),
client,
Expand Down
7 changes: 5 additions & 2 deletions src/Exthost/SignatureHelp.re
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,13 @@ module Signature = {
);
};

[@deriving show]
type cacheId = int;

module Response = {
[@deriving show]
type t = {
id: int,
cacheId,
signatures: list(Signature.t),
activeSignature: int,
activeParameter: int,
Expand All @@ -135,7 +138,7 @@ module Response = {
Json.Decode.(
obj(({field, _}) =>
{
id: field.required("id", int),
cacheId: field.required("id", int),
signatures: field.required("signatures", list(Signature.decode)),
activeSignature: field.required("activeSignature", int),
activeParameter: field.required("activeParameter", int),
Expand Down
7 changes: 6 additions & 1 deletion src/Exthost/SuggestResult.re
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
open Oni_Core;

[@deriving show]
type cacheId = int;

[@deriving show]
type t = {
completions: list(SuggestItem.t),
isIncomplete: bool,
cacheId: option(cacheId),
};

let empty = {completions: [], isIncomplete: false};
let empty = {completions: [], isIncomplete: false, cacheId: None};

module Dto = {
let decode = {
Expand All @@ -17,6 +21,7 @@ module Dto = {
// https://github.com/onivim/vscode-exthost/blob/50bef147f7bbd250015361a4e3cad3305f65bc27/src/vs/workbench/api/common/extHost.protocol.ts#L1129
completions: field.required("b", list(SuggestItem.Dto.decode)),
isIncomplete: field.withDefault("c", false, bool),
cacheId: field.optional("x", int),
}
)
);
Expand Down
10 changes: 5 additions & 5 deletions src/Feature/LanguageSupport/CodeLens.re
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ module Log = (

// MODEL

type codeLens = Exthost.CodeLens.t;
type codeLens = Exthost.CodeLens.lens;

let lineNumber = (lens: Exthost.CodeLens.t) =>
let lineNumber = (lens: Exthost.CodeLens.lens) =>
Exthost.OneBasedRange.(lens.range.startLineNumber - 1);

let textFromExthost = (lens: Exthost.CodeLens.t) => {
let textFromExthost = (lens: Exthost.CodeLens.lens) => {
Exthost.Command.(
lens.command
|> OptionEx.flatMap(command => command.label)
Expand All @@ -21,7 +21,7 @@ let textFromExthost = (lens: Exthost.CodeLens.t) => {
);
};

let text = (lens: Exthost.CodeLens.t) => textFromExthost(lens);
let text = (lens: Exthost.CodeLens.lens) => textFromExthost(lens);

type provider = {
handle: int,
Expand Down Expand Up @@ -55,7 +55,7 @@ type msg =
bufferId: int,
startLine: EditorCoreTypes.LineNumber.t,
stopLine: EditorCoreTypes.LineNumber.t,
lenses: list(Exthost.CodeLens.t),
lenses: list(Exthost.CodeLens.lens),
});

let register = (~handle: int, ~selector, ~maybeEventHandle, model) => {
Expand Down
2 changes: 1 addition & 1 deletion src/Feature/LanguageSupport/Feature_LanguageSupport.rei
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Msg: {
};

module CodeLens: {
type t = Exthost.CodeLens.t;
type t = Exthost.CodeLens.lens;

let lineNumber: t => int;
let text: t => string;
Expand Down
Loading