Skip to content

Commit

Permalink
fix(signature help/onivim#1980): close on buffer updates (onivim#1981)
Browse files Browse the repository at this point in the history
* Fix signature help not closing on buffer changes

* Features: update signatureHelp state
  • Loading branch information
zbaylin authored Jul 22, 2020
1 parent 2bb59e0 commit f4e0b96
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
52 changes: 50 additions & 2 deletions src/Feature/SignatureHelp/Feature_SignatureHelp.re
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
open Oni_Core;
open EditorCoreTypes;

module Log = (val Log.withNamespace("Oni.Feature.SignatureHelp"));
module Log = (val Log.withNamespace("Oni2.Feature.SignatureHelp"));
module IDGenerator =
Utility.IDGenerator.Make({});

Expand All @@ -24,6 +24,8 @@ type model = {
activeSignature: option(int),
activeParameter: option(int),
editorID: option(int),
location: option(Location.t),
context: option(Exthost.SignatureHelp.RequestContext.t),
};

let initial = {
Expand All @@ -35,6 +37,8 @@ let initial = {
activeSignature: None,
activeParameter: None,
editorID: None,
location: None,
context: None,
};

[@deriving show({with_path: false})]
Expand All @@ -54,11 +58,14 @@ type msg =
activeParameter: int,
requestID: int,
editorID: int,
location: Location.t,
context: Exthost.SignatureHelp.RequestContext.t,
})
| EmptyInfoReceived(int)
| RequestFailed(string)
| SignatureIncrementClicked
| SignatureDecrementClicked;
| SignatureDecrementClicked
| CursorMoved(int);

type outmsg =
| Nothing
Expand Down Expand Up @@ -135,6 +142,8 @@ let getEffectsForLocation =
activeParameter,
requestID,
editorID: Feature_Editor.Editor.getId(editor),
location,
context,
})
| Ok(None) => EmptyInfoReceived(requestID)
| Error(s) => RequestFailed(s)
Expand Down Expand Up @@ -189,6 +198,8 @@ let update = (~maybeBuffer, ~maybeEditor, ~extHostClient, model, msg) =>
activeParameter,
requestID,
editorID,
location,
context,
}) =>
switch (model.lastRequestID) {
| Some(reqID) when reqID == requestID => (
Expand All @@ -198,6 +209,8 @@ let update = (~maybeBuffer, ~maybeEditor, ~extHostClient, model, msg) =>
activeSignature: Some(activeSignature),
activeParameter: Some(activeParameter),
editorID: Some(editorID),
location: Some(location),
context: Some(context),
},
Nothing,
)
Expand Down Expand Up @@ -348,6 +361,41 @@ let update = (~maybeBuffer, ~maybeEditor, ~extHostClient, model, msg) =>
},
Nothing,
)
| CursorMoved(editorID) =>
switch (model.editorID, maybeEditor, maybeBuffer, model.context) {
| (Some(editorID'), Some(editor), Some(buffer), Some(context))
when
editorID == editorID'
&& editorID == Feature_Editor.Editor.getId(editor) =>
let cursorLocation = Feature_Editor.Editor.getPrimaryCursor(editor);
let loc =
Index.(
Location.create(
~line=cursorLocation.line,
~column=cursorLocation.column + 1,
)
);
switch (model.location) {
| Some(location) when location == loc =>
let requestID = IDGenerator.get();
let effects =
getEffectsForLocation(
~buffer,
~editor,
~location=cursorLocation,
~extHostClient,
~model,
~context,
~requestID,
);
(
{...model, shown: true, lastRequestID: Some(requestID)},
Effect(effects),
);
| _ => (model, Nothing)
};
| _ => (model, Nothing)
}
};

module View = {
Expand Down
5 changes: 4 additions & 1 deletion src/Feature/SignatureHelp/Feature_SignatureHelp.rei
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ type msg =
activeParameter: int,
requestID: int,
editorID: int,
location: EditorCoreTypes.Location.t,
context: Exthost.SignatureHelp.RequestContext.t,
})
| EmptyInfoReceived(int)
| RequestFailed(string)
| SignatureIncrementClicked
| SignatureDecrementClicked;
| SignatureDecrementClicked
| CursorMoved(int);

type outmsg =
| Nothing
Expand Down
24 changes: 24 additions & 0 deletions src/Store/Features.re
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,30 @@ let update =
);
(state, eff);

| Editor({scope, msg: CursorsChanged(_) as msg}) =>
let maybeBuffer = Selectors.getActiveBuffer(state);
let editor = Feature_Layout.activeEditor(state.layout);
let (signatureHelp, shOutMsg) =
Feature_SignatureHelp.update(
~maybeBuffer,
~maybeEditor=Some(editor),
~extHostClient,
state.signatureHelp,
Feature_SignatureHelp.CursorMoved(
Feature_Editor.Editor.getId(editor),
),
);
let shEffect =
switch (shOutMsg) {
| Effect(e) => Effect.map(msg => Actions.SignatureHelp(msg), e)
| _ => Effect.none
};
let (layout, editorEffect) =
Internal.updateEditors(~scope, ~msg, state.layout);
let state = {...state, layout, signatureHelp};
let effect = [shEffect, editorEffect] |> Effect.batch;
(state, effect);

| Editor({scope, msg}) =>
let (layout, effect) =
Internal.updateEditors(~scope, ~msg, state.layout);
Expand Down

0 comments on commit f4e0b96

Please sign in to comment.