Skip to content

Commit 7aa664b

Browse files
mmahroussfda-odoo
authored andcommitted
[IMP] vscode,server: add tooltip, fix disabled behavior
1 parent 83ca890 commit 7aa664b

File tree

3 files changed

+58
-37
lines changed

3 files changed

+58
-37
lines changed

server/src/core/config.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ fn process_version(var: Sourced<String>, ws_folders: &HashMap<String, String>, w
473473

474474
#[derive(Debug, Clone, Deserialize, Serialize)]
475475
pub struct ConfigEntryRaw {
476-
#[serde(default = "default_name")]
476+
#[serde(default = "default_profile_name")]
477477
pub name: String,
478478

479479
#[serde(default, serialize_with = "serialize_option_as_default")]
@@ -528,7 +528,7 @@ pub struct ConfigEntryRaw {
528528
impl Default for ConfigEntryRaw {
529529
fn default() -> Self {
530530
Self {
531-
name: default_name(),
531+
name: default_profile_name(),
532532
extends: None,
533533
odoo_path: None,
534534
addons_merge: None,
@@ -574,6 +574,7 @@ impl ConfigEntryRaw {
574574

575575
#[derive(Debug, Clone)]
576576
pub struct ConfigEntry {
577+
pub name: String,
577578
pub odoo_path: Option<String>,
578579
pub addons_paths: HashSet<String>,
579580
pub python_path: String,
@@ -592,6 +593,7 @@ pub struct ConfigEntry {
592593
impl Default for ConfigEntry {
593594
fn default() -> Self {
594595
Self {
596+
name: default_profile_name(),
595597
odoo_path: None,
596598
addons_paths: HashSet::new(),
597599
python_path: S!(DEFAULT_PYTHON),
@@ -618,7 +620,7 @@ impl ConfigEntry {
618620
pub type ConfigNew = HashMap<String, ConfigEntry>;
619621

620622

621-
fn default_name() -> String {
623+
pub fn default_profile_name() -> String {
622624
"default".to_string()
623625
}
624626

@@ -1104,8 +1106,9 @@ fn merge_all_workspaces(
11041106
let mut final_config: ConfigNew = HashMap::new();
11051107
for (key, raw_entry) in merged_raw_config {
11061108
final_config.insert(
1107-
key,
1109+
key.clone(),
11081110
ConfigEntry {
1111+
name: key.clone(),
11091112
odoo_path: raw_entry.odoo_path.map(|op| op.value),
11101113
addons_paths: raw_entry.addons_paths.into_iter().flatten().map(|op| op.value).collect(),
11111114
python_path: raw_entry.python_path.map(|op| op.value).unwrap_or(S!(DEFAULT_PYTHON)),

server/src/core/odoo.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::path::{Path, PathBuf};
2525
use std::env;
2626
use regex::Regex;
2727
use crate::{constants::*, oyarn, Sy};
28-
use super::config::{self, get_configuration, ConfigEntry, ConfigFile, RefreshMode};
28+
use super::config::{self, default_profile_name, get_configuration, ConfigEntry, ConfigFile, RefreshMode};
2929
use super::entry_point::{EntryPoint, EntryPointMgr};
3030
use super::file_mgr::FileMgr;
3131
use super::import_resolver::ImportCache;
@@ -983,23 +983,21 @@ impl Odoo {
983983
}
984984
};
985985
let selected_config = match maybe_selected_config {
986-
None => {
987-
session.show_message(MessageType::INFO, String::from("No Odoo configuration selected. Please select a configuration in the settings."));
988-
return;
989-
}
990-
Some(c) if c == "" => {
991-
session.show_message(MessageType::INFO, String::from("No Odoo configuration selected. Please select a configuration in the settings."));
992-
return;
993-
}
986+
None => default_profile_name(),
987+
Some(c) if c == "" => default_profile_name(),
994988
Some(config) => config,
995989
};
990+
if selected_config == "Disabled" {
991+
info!("OdooLS is disabled. Exiting...");
992+
return;
993+
}
996994
let config = config.and_then(|(ce, _)|{
997995
ce.get(&selected_config).cloned().ok_or(format!("Unable to find selected configuration \"{}\"", &selected_config))
998996
});
999997
match config {
1000998
Ok(config) => {
1001999
if config.abstract_ {
1002-
session.show_message(MessageType::ERROR, format!("Selected configuration ({}) is abstract. Please select a valid configuration and restart.", selected_config));
1000+
session.show_message(MessageType::ERROR, format!("Selected configuration ({}) is abstract. Please select a valid configuration and restart.", config.name));
10031001
return;
10041002
}
10051003
SyncOdoo::init(session, config);
@@ -1470,9 +1468,7 @@ impl Odoo {
14701468
if Odoo::is_config_workspace_file(session, path) {
14711469
let config_result = config::get_configuration(session.sync_odoo.get_file_mgr().borrow().get_workspace_folders())
14721470
.and_then(|(cfg_map, cfg_file)| {
1473-
let Some(config_name) = Odoo::read_selected_configuration(session)? else {
1474-
return Err(S!("No configuration selected"));
1475-
};
1471+
let config_name = Odoo::read_selected_configuration(session)?.unwrap_or(default_profile_name());
14761472
cfg_map.get(&config_name)
14771473
.cloned()
14781474
.ok_or_else(|| format!("Unable to find selected configuration \"{config_name}\""))

vscode/client/extension.ts

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
Range,
2222
TextEditor,
2323
DecorationOptions,
24+
MarkdownString,
2425
} from "vscode";
2526
import {
2627
LanguageClientOptions,
@@ -50,11 +51,6 @@ import { ThemeIcon } from "vscode";
5051
let CONFIG_HTML_MAP: Record<string, string> = {};
5152
let CONFIG_FILE: any = undefined;
5253

53-
function handleSetConfigurationNotification(payload: { html: Record<string, string>, configFile: any }) {
54-
CONFIG_HTML_MAP = payload.html || {};
55-
CONFIG_FILE = payload.configFile;
56-
}
57-
5854
function getClientOptions(): LanguageClientOptions {
5955
return {
6056
// Register the server for plain text documents
@@ -206,18 +202,44 @@ function startLangServer(
206202
return new SafeLanguageClient('odooServer', 'Odoo Server', serverOptions, clientOptions);
207203
}
208204

205+
const RESTART_COMMAND_MD = `[$(list-unordered) Show all configurations](command:odoo.showServerConfig "Show all configurations")\n
206+
[$(debug-restart) Reload Server and Configuration](command:odoo.restartServer "Reload Server and Configuration")`;
207+
209208
async function setStatusConfig(context: ExtensionContext) {
210209
const config = await getCurrentConfig(context);
211-
let text = (config ? `Odoo (${config})` : `Odoo (Disabled)`);
210+
let text = (config ? `Odoo (${config})` : `Odoo (Default)`);
212211
global.STATUS_BAR.text = (global.IS_LOADING) ? "$(loading~spin) " + text : text;
213-
}
214212

213+
let tooltipMd = '';
214+
if (config && config !== 'Disabled') {
215+
let configEntry = getCurrentConfigEntry(context);
216+
if (configEntry) {
217+
const odooPath = configEntry.odoo_path?.value || configEntry.odoo_path || '';
218+
const pythonPath = configEntry.python_path?.value || configEntry.python_path || '';
219+
let addonsPaths: string[] = [];
220+
if (Array.isArray(configEntry.addons_paths)) {
221+
addonsPaths = configEntry.addons_paths.map((a: any) => a.value || a).filter(Boolean);
222+
}
223+
tooltipMd += `**Odoo Path:** ${odooPath || 'Not set'} \n`;
224+
tooltipMd += `**Addons Paths:** \n`
215225

226+
if (addonsPaths.length > 0) {
227+
for (const ap of addonsPaths) {
228+
tooltipMd += ` - ${ap} \n`;
229+
}
230+
} else {
231+
tooltipMd += ` Not set \n`;
232+
}
233+
tooltipMd += `\n\n**Python Path:** ${pythonPath || 'Not set'} \n`;
234+
tooltipMd += `\n---\n`;
235+
}
236+
}
237+
tooltipMd += RESTART_COMMAND_MD;
238+
global.STATUS_BAR.tooltip = new MarkdownString(tooltipMd, true);
239+
global.STATUS_BAR.tooltip.isTrusted = {enabledCommands: ["odoo.restartServer", "odoo.showServerConfig"]};
240+
}
216241
async function changeSelectedConfig(context: ExtensionContext, configName: string) {
217242
try {
218-
if (configName == "Disabled"){
219-
configName = undefined;
220-
}
221243
await workspace.getConfiguration().update("Odoo.selectedProfile", configName, ConfigurationTarget.Workspace);
222244
return true;
223245
} catch (err) {
@@ -323,7 +345,16 @@ async function initLanguageServerClient(context: ExtensionContext, outputChannel
323345
client.onNotification("$Odoo/setPid", async(params) => {
324346
global.SERVER_PID = params["server_pid"];
325347
}),
326-
client.onNotification("$Odoo/setConfiguration", handleSetConfigurationNotification),
348+
client.onNotification("$Odoo/setConfiguration", async (payload: { html: Record<string, string>, configFile: any }) => {
349+
CONFIG_HTML_MAP = payload.html || {};
350+
CONFIG_FILE = payload.configFile;
351+
const selected = workspace.getConfiguration().get("Odoo.selectedProfile") as string;
352+
if (selected === "Disabled" ){
353+
// Stop the client if the selected profile is "Disabled"
354+
// We already got the configurations
355+
global.LSCLIENT.stop();
356+
}
357+
}),
327358
client.onNotification("$Odoo/invalid_python_path", async(params) => {
328359
await window.showErrorMessage(
329360
"The Odoo extension is unable to start Python with the path you provided. Verify your configuration"
@@ -385,18 +416,9 @@ function deleteOldFiles(context: ExtensionContext) {
385416
async function initStatusBar(context: ExtensionContext): Promise<void> {
386417
global.STATUS_BAR = window.createStatusBarItem(StatusBarAlignment.Left, 100);
387418
global.STATUS_BAR.command = "odoo.clickStatusBar";
388-
global.STATUS_BAR.tooltip = "Odoo: Change Configuration";
389419
context.subscriptions.push(global.STATUS_BAR);
390420
await setStatusConfig(context);
391421
global.STATUS_BAR.show();
392-
393-
// Add a restart button to the status bar
394-
global.STATUS_BAR_RESTART = window.createStatusBarItem(StatusBarAlignment.Left, 99);
395-
global.STATUS_BAR_RESTART.text = "$(refresh)";
396-
global.STATUS_BAR_RESTART.tooltip = "Odoo: Restart Language Server";
397-
global.STATUS_BAR_RESTART.command = "odoo.restartServer";
398-
context.subscriptions.push(global.STATUS_BAR_RESTART);
399-
global.STATUS_BAR_RESTART.show();
400422
}
401423

402424

0 commit comments

Comments
 (0)