mirror of https://github.com/lapce/lapce.git
fix plugin can't upgrade issue (#1737)
* fix plugin can't upgrade issue * update changelog
This commit is contained in:
parent
54ff5c7e3c
commit
c355bb2fe2
|
@ -12,6 +12,7 @@
|
|||
> This is a breaking change
|
||||
|
||||
### Bug Fixes
|
||||
- [#1737](https://github.com/lapce/lapce/pull/1726): Fix an issue that plugins can't be upgraded
|
||||
|
||||
- [#1724](https://github.com/lapce/lapce/pull/1724): files and hidden folders no longer will be considered when trying to open a plugin base folder
|
||||
|
||||
|
|
|
@ -612,6 +612,7 @@ pub enum LapceUICommand {
|
|||
UpdatePickerPwd(PathBuf),
|
||||
UpdatePickerItems(PathBuf, HashMap<PathBuf, FileNodeItem>),
|
||||
UpdateExplorerItems(PathBuf, HashMap<PathBuf, FileNodeItem>, bool),
|
||||
LoadPluginLatest(VoltInfo),
|
||||
LoadPlugins(PluginsInfo),
|
||||
LoadPluginsFailed,
|
||||
LoadPluginIcon(String, VoltIconKind),
|
||||
|
|
|
@ -1199,8 +1199,12 @@ pub fn do_edit(
|
|||
modal,
|
||||
register,
|
||||
);
|
||||
self.buffer_mut().set_cursor_before(old_cursor);
|
||||
self.buffer_mut().set_cursor_after(cursor.mode.clone());
|
||||
|
||||
if !deltas.is_empty() {
|
||||
self.buffer_mut().set_cursor_before(old_cursor);
|
||||
self.buffer_mut().set_cursor_after(cursor.mode.clone());
|
||||
}
|
||||
|
||||
self.apply_deltas(&deltas);
|
||||
deltas
|
||||
}
|
||||
|
|
|
@ -464,6 +464,28 @@ fn resolve_code_action(
|
|||
)
|
||||
}
|
||||
|
||||
fn completion_do_edit(
|
||||
&mut self,
|
||||
selection: &Selection,
|
||||
edits: &[(impl AsRef<Selection>, &str)],
|
||||
) {
|
||||
let old_cursor = self.editor.cursor.mode.clone();
|
||||
let doc = Arc::make_mut(&mut self.doc);
|
||||
let (delta, inval_lines, edits) =
|
||||
doc.do_raw_edit(edits, EditType::Completion);
|
||||
let selection = selection.apply_delta(&delta, true, InsertDrift::Default);
|
||||
Arc::make_mut(&mut self.editor)
|
||||
.cursor
|
||||
.update_selection(self.doc.buffer(), selection);
|
||||
|
||||
let doc = Arc::make_mut(&mut self.doc);
|
||||
doc.buffer_mut().set_cursor_before(old_cursor);
|
||||
doc.buffer_mut()
|
||||
.set_cursor_after(self.editor.cursor.mode.clone());
|
||||
|
||||
self.apply_deltas(&[(delta, inval_lines, edits)]);
|
||||
}
|
||||
|
||||
pub fn apply_completion_item(&mut self, item: &CompletionItem) -> Result<()> {
|
||||
let additional_edit: Option<Vec<_>> =
|
||||
item.additional_text_edits.as_ref().map(|edits| {
|
||||
|
@ -506,29 +528,20 @@ pub fn apply_completion_item(&mut self, item: &CompletionItem) -> Result<()> {
|
|||
);
|
||||
match text_format {
|
||||
lsp_types::InsertTextFormat::PLAIN_TEXT => {
|
||||
let (delta, inval_lines, edits) =
|
||||
Arc::make_mut(&mut self.doc).do_raw_edit(
|
||||
&[
|
||||
&[(&selection, edit.new_text.as_str())][..],
|
||||
&additional_edit[..],
|
||||
]
|
||||
.concat(),
|
||||
EditType::Completion,
|
||||
);
|
||||
let selection = selection.apply_delta(
|
||||
&delta,
|
||||
true,
|
||||
InsertDrift::Default,
|
||||
self.completion_do_edit(
|
||||
&selection,
|
||||
&[
|
||||
&[(&selection, edit.new_text.as_str())][..],
|
||||
&additional_edit[..],
|
||||
]
|
||||
.concat(),
|
||||
);
|
||||
Arc::make_mut(&mut self.editor)
|
||||
.cursor
|
||||
.update_selection(self.doc.buffer(), selection);
|
||||
self.apply_deltas(&[(delta, inval_lines, edits)]);
|
||||
return Ok(());
|
||||
}
|
||||
lsp_types::InsertTextFormat::SNIPPET => {
|
||||
let snippet = Snippet::from_str(&edit.new_text)?;
|
||||
let text = snippet.text();
|
||||
let old_cursor = self.editor.cursor.mode.clone();
|
||||
let (delta, inval_lines, edits) =
|
||||
Arc::make_mut(&mut self.doc).do_raw_edit(
|
||||
&[
|
||||
|
@ -562,6 +575,13 @@ pub fn apply_completion_item(&mut self, item: &CompletionItem) -> Result<()> {
|
|||
Arc::make_mut(&mut self.editor)
|
||||
.cursor
|
||||
.update_selection(self.doc.buffer(), selection);
|
||||
|
||||
let doc = Arc::make_mut(&mut self.doc);
|
||||
doc.buffer_mut().set_cursor_before(old_cursor);
|
||||
doc.buffer_mut().set_cursor_after(
|
||||
self.editor.cursor.mode.clone(),
|
||||
);
|
||||
|
||||
self.apply_deltas(&[(delta, inval_lines, edits)]);
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -576,6 +596,12 @@ pub fn apply_completion_item(&mut self, item: &CompletionItem) -> Result<()> {
|
|||
Arc::make_mut(&mut self.editor)
|
||||
.cursor
|
||||
.set_insert(selection);
|
||||
|
||||
let doc = Arc::make_mut(&mut self.doc);
|
||||
doc.buffer_mut().set_cursor_before(old_cursor);
|
||||
doc.buffer_mut()
|
||||
.set_cursor_after(self.editor.cursor.mode.clone());
|
||||
|
||||
self.apply_deltas(&[(delta, inval_lines, edits)]);
|
||||
Arc::make_mut(&mut self.editor)
|
||||
.add_snippet_placeholders(snippet_tabs);
|
||||
|
@ -593,7 +619,8 @@ pub fn apply_completion_item(&mut self, item: &CompletionItem) -> Result<()> {
|
|||
let end_offset = self.doc.buffer().next_code_boundary(offset);
|
||||
let selection = Selection::region(start_offset, end_offset);
|
||||
|
||||
let (delta, inval_lines, edits) = Arc::make_mut(&mut self.doc).do_raw_edit(
|
||||
self.completion_do_edit(
|
||||
&selection,
|
||||
&[
|
||||
&[(
|
||||
&selection,
|
||||
|
@ -602,13 +629,7 @@ pub fn apply_completion_item(&mut self, item: &CompletionItem) -> Result<()> {
|
|||
&additional_edit[..],
|
||||
]
|
||||
.concat(),
|
||||
EditType::Completion,
|
||||
);
|
||||
let selection = selection.apply_delta(&delta, true, InsertDrift::Default);
|
||||
Arc::make_mut(&mut self.editor)
|
||||
.cursor
|
||||
.update_selection(self.doc.buffer(), selection);
|
||||
self.apply_deltas(&[(delta, inval_lines, edits)]);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -145,6 +145,7 @@ pub struct PluginData {
|
|||
pub volts: VoltsList,
|
||||
pub installing: IndexMap<String, PluginInstallStatus>,
|
||||
pub installed: IndexMap<String, VoltMetadata>,
|
||||
pub installed_latest: IndexMap<String, VoltInfo>,
|
||||
pub installed_icons: im::HashMap<String, VoltIconKind>,
|
||||
pub disabled: HashSet<String>,
|
||||
pub workspace_disabled: HashSet<String>,
|
||||
|
@ -185,6 +186,7 @@ pub fn new(
|
|||
volts: VoltsList::new(tab_id, event_sink),
|
||||
installing: IndexMap::new(),
|
||||
installed: IndexMap::new(),
|
||||
installed_latest: IndexMap::new(),
|
||||
installed_icons: im::HashMap::new(),
|
||||
disabled: HashSet::from_iter(disabled.into_iter()),
|
||||
workspace_disabled: HashSet::from_iter(workspace_disabled.into_iter()),
|
||||
|
@ -218,11 +220,15 @@ pub fn plugin_status(&self, id: &str) -> PluginStatus {
|
|||
}
|
||||
|
||||
if let Some(meta) = self.installed.get(id) {
|
||||
if let Some(volt) = self.volts.volts.get(id) {
|
||||
if let Some(volt) = self
|
||||
.installed_latest
|
||||
.get(id)
|
||||
.or_else(|| self.volts.volts.get(id))
|
||||
{
|
||||
if meta.version == volt.version {
|
||||
PluginStatus::Installed
|
||||
} else {
|
||||
PluginStatus::Upgrade
|
||||
PluginStatus::Upgrade(volt.version.clone())
|
||||
}
|
||||
} else {
|
||||
PluginStatus::Installed
|
||||
|
@ -406,12 +412,47 @@ pub fn remove_volt(proxy: Arc<LapceProxy>, meta: VoltMetadata) -> Result<()> {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn volt_installed(
|
||||
&mut self,
|
||||
tab_id: WidgetId,
|
||||
volt: &VoltMetadata,
|
||||
icon: &Option<String>,
|
||||
event_sink: ExtEventSink,
|
||||
) {
|
||||
let volt_id = volt.id();
|
||||
|
||||
self.installing.remove(&volt_id);
|
||||
self.installed.insert(volt_id.clone(), volt.clone());
|
||||
|
||||
if let Some(icon) = icon.as_ref().and_then(|icon| {
|
||||
VoltIconKind::from_bytes(&base64::decode(icon).ok()?).ok()
|
||||
}) {
|
||||
self.installed_icons.insert(volt_id.clone(), icon);
|
||||
}
|
||||
|
||||
if !self.volts.volts.contains_key(&volt_id) {
|
||||
let url = format!(
|
||||
"https://plugins.lapce.dev/api/v1/plugins/{}/{}/latest",
|
||||
volt.author, volt.name
|
||||
);
|
||||
std::thread::spawn(move || -> Result<()> {
|
||||
let info: VoltInfo = reqwest::blocking::get(url)?.json()?;
|
||||
let _ = event_sink.submit_command(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::LoadPluginLatest(info),
|
||||
Target::Widget(tab_id),
|
||||
);
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Display, PartialEq, Eq, Clone)]
|
||||
pub enum PluginStatus {
|
||||
Installed,
|
||||
Install,
|
||||
Upgrade,
|
||||
Upgrade(String),
|
||||
Disabled,
|
||||
}
|
||||
|
|
|
@ -383,7 +383,7 @@ fn paint_plugin(
|
|||
|
||||
let color = match status {
|
||||
PluginStatus::Installed => LapceTheme::LAPCE_PLUGIN_AUTHOR,
|
||||
PluginStatus::Upgrade => LapceTheme::LAPCE_WARN,
|
||||
PluginStatus::Upgrade(_) => LapceTheme::LAPCE_WARN,
|
||||
_ => LapceTheme::EDITOR_DIM,
|
||||
};
|
||||
|
||||
|
@ -1214,8 +1214,9 @@ fn status_on_click(ctx: &mut EventCtx, data: &LapceTabData, id: &str, pos: Point
|
|||
if let Some(meta) = data.plugin.installed.get(id) {
|
||||
let mut menu = druid::Menu::<LapceData>::new("Plugin");
|
||||
|
||||
if let PluginStatus::Upgrade = status {
|
||||
let info = meta.info();
|
||||
if let PluginStatus::Upgrade(latest_version) = status {
|
||||
let mut info = meta.info();
|
||||
info.version = latest_version;
|
||||
let proxy = data.proxy.clone();
|
||||
let item = druid::MenuItem::new("Upgrade Plugin").on_activate(
|
||||
move |_ctx, _data, _env| {
|
||||
|
|
|
@ -38,10 +38,7 @@
|
|||
PanelContainerPosition, PanelKind, PanelPosition, PanelResizePosition,
|
||||
PanelStyle,
|
||||
},
|
||||
plugin::{
|
||||
plugin_install_status::{PluginInstallStatus, PluginInstallType},
|
||||
VoltIconKind,
|
||||
},
|
||||
plugin::plugin_install_status::{PluginInstallStatus, PluginInstallType},
|
||||
proxy::path_from_url,
|
||||
signature::SignatureStatus,
|
||||
};
|
||||
|
@ -975,6 +972,11 @@ fn handle_command_event(
|
|||
}
|
||||
ctx.set_handled();
|
||||
}
|
||||
LapceUICommand::LoadPluginLatest(info) => {
|
||||
ctx.set_handled();
|
||||
let plugin = Arc::make_mut(&mut data.plugin);
|
||||
plugin.installed_latest.insert(info.id(), info.clone());
|
||||
}
|
||||
LapceUICommand::LoadPlugins(info) => {
|
||||
ctx.set_handled();
|
||||
let plugin = Arc::make_mut(&mut data.plugin);
|
||||
|
@ -992,18 +994,12 @@ fn handle_command_event(
|
|||
}
|
||||
LapceUICommand::VoltInstalled(volt, icon) => {
|
||||
let plugin = Arc::make_mut(&mut data.plugin);
|
||||
|
||||
// if there is a value inside the installing map, remove it from there as soon as it is installed.
|
||||
plugin.installing.remove(&volt.id());
|
||||
|
||||
plugin.installed.insert(volt.id(), volt.clone());
|
||||
|
||||
if let Some(icon) = icon.as_ref().and_then(|icon| {
|
||||
VoltIconKind::from_bytes(&base64::decode(icon).ok()?)
|
||||
.ok()
|
||||
}) {
|
||||
plugin.installed_icons.insert(volt.id(), icon);
|
||||
}
|
||||
plugin.volt_installed(
|
||||
data.id,
|
||||
volt,
|
||||
icon,
|
||||
ctx.get_external_handle(),
|
||||
);
|
||||
|
||||
for (_, tabs) in data.main_split.editor_tabs.iter() {
|
||||
for child in tabs.children.iter() {
|
||||
|
|
Loading…
Reference in New Issue