Skip to content

Commit 1cc08c8

Browse files
authored
Merge pull request #890 from posit-dev/bugfix/open-file-uri
Send `OpenFile` request with `kind` field
2 parents 28d4346 + 3e05369 commit 1cc08c8

File tree

7 files changed

+47
-18
lines changed

7 files changed

+47
-18
lines changed

crates/amalthea/src/comm/data_explorer_comm.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ pub enum SearchSchemaSortOrder {
714714
}
715715

716716
/// Possible values for ColumnDisplayType
717-
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display)]
717+
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
718718
pub enum ColumnDisplayType {
719719
#[serde(rename = "number")]
720720
#[strum(to_string = "number")]
@@ -762,7 +762,7 @@ pub enum ColumnDisplayType {
762762
}
763763

764764
/// Possible values for Condition in RowFilter
765-
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display)]
765+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
766766
pub enum RowFilterCondition {
767767
#[serde(rename = "and")]
768768
#[strum(to_string = "and")]
@@ -774,7 +774,7 @@ pub enum RowFilterCondition {
774774
}
775775

776776
/// Possible values for RowFilterType
777-
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display)]
777+
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
778778
pub enum RowFilterType {
779779
#[serde(rename = "between")]
780780
#[strum(to_string = "between")]
@@ -822,7 +822,7 @@ pub enum RowFilterType {
822822
}
823823

824824
/// Possible values for Op in FilterComparison
825-
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display)]
825+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
826826
pub enum FilterComparisonOp {
827827
#[serde(rename = "=")]
828828
#[strum(to_string = "=")]
@@ -850,7 +850,7 @@ pub enum FilterComparisonOp {
850850
}
851851

852852
/// Possible values for TextSearchType
853-
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display)]
853+
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
854854
pub enum TextSearchType {
855855
#[serde(rename = "contains")]
856856
#[strum(to_string = "contains")]
@@ -874,7 +874,7 @@ pub enum TextSearchType {
874874
}
875875

876876
/// Possible values for ColumnFilterType
877-
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display)]
877+
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
878878
pub enum ColumnFilterType {
879879
#[serde(rename = "text_search")]
880880
#[strum(to_string = "text_search")]
@@ -886,7 +886,7 @@ pub enum ColumnFilterType {
886886
}
887887

888888
/// Possible values for ColumnProfileType
889-
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display)]
889+
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
890890
pub enum ColumnProfileType {
891891
#[serde(rename = "null_count")]
892892
#[strum(to_string = "null_count")]
@@ -914,7 +914,7 @@ pub enum ColumnProfileType {
914914
}
915915

916916
/// Possible values for Method in ColumnHistogramParams
917-
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display)]
917+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
918918
pub enum ColumnHistogramParamsMethod {
919919
#[serde(rename = "sturges")]
920920
#[strum(to_string = "sturges")]
@@ -934,7 +934,7 @@ pub enum ColumnHistogramParamsMethod {
934934
}
935935

936936
/// Possible values for Kind in TableSelection
937-
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display)]
937+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
938938
pub enum TableSelectionKind {
939939
#[serde(rename = "single_cell")]
940940
#[strum(to_string = "single_cell")]
@@ -962,7 +962,7 @@ pub enum TableSelectionKind {
962962
}
963963

964964
/// Possible values for ExportFormat
965-
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display)]
965+
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
966966
pub enum ExportFormat {
967967
#[serde(rename = "csv")]
968968
#[strum(to_string = "csv")]
@@ -978,7 +978,7 @@ pub enum ExportFormat {
978978
}
979979

980980
/// Possible values for SupportStatus
981-
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display)]
981+
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
982982
pub enum SupportStatus {
983983
#[serde(rename = "unsupported")]
984984
#[strum(to_string = "unsupported")]

crates/amalthea/src/comm/help_comm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use serde::Deserialize;
1212
use serde::Serialize;
1313

1414
/// Possible values for Kind in ShowHelp
15-
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display)]
15+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
1616
pub enum ShowHelpKind {
1717
#[serde(rename = "html")]
1818
#[strum(to_string = "html")]

crates/amalthea/src/comm/plot_comm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub struct PlotRenderSettings {
6464
}
6565

6666
/// Possible values for PlotUnit
67-
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display)]
67+
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
6868
pub enum PlotUnit {
6969
#[serde(rename = "pixels")]
7070
#[strum(to_string = "pixels")]
@@ -76,7 +76,7 @@ pub enum PlotUnit {
7676
}
7777

7878
/// Possible values for PlotRenderFormat
79-
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display)]
79+
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
8080
pub enum PlotRenderFormat {
8181
#[serde(rename = "png")]
8282
#[strum(to_string = "png")]

crates/amalthea/src/comm/ui_comm.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ pub struct Range {
9898
pub end: Position
9999
}
100100

101+
/// Possible values for Kind in OpenEditor
102+
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, strum_macros::Display, strum_macros::EnumString)]
103+
pub enum OpenEditorKind {
104+
#[serde(rename = "path")]
105+
#[strum(to_string = "path")]
106+
Path,
107+
108+
#[serde(rename = "uri")]
109+
#[strum(to_string = "uri")]
110+
Uri
111+
}
112+
101113
/// Parameters for the DidChangePlotsRenderSettings method.
102114
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
103115
pub struct DidChangePlotsRenderSettingsParams {
@@ -133,6 +145,10 @@ pub struct OpenEditorParams {
133145

134146
/// The column number to jump to
135147
pub column: i64,
148+
149+
/// How to interpret the 'file' argument: as a file path or as a URI. If
150+
/// omitted, defaults to 'path'.
151+
pub kind: OpenEditorKind,
136152
}
137153

138154
/// Parameters for the NewDocument method.

crates/ark/src/modules/positron/frontend-methods.R

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@
3939
column = 0L
4040
) {
4141
# Don't normalize if that's an `ark:` URI
42-
if (!grepl("^ark:", file)) {
42+
if (is_ark_uri(file)) {
43+
kind <- "uri"
44+
} else {
45+
kind <- "path"
4346
file <- normalizePath(file)
4447
}
4548

@@ -51,7 +54,7 @@
5154
column <- 0L
5255
}
5356

54-
.ps.Call("ps_ui_navigate_to_file", file, line, column)
57+
.ps.Call("ps_ui_navigate_to_file", file, line, column, kind)
5558
}
5659

5760
#' @export

crates/ark/src/modules/positron/srcref.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ srcref_info <- function(srcref) {
118118
lines <- srcfile$lines
119119

120120
if (!identical(file, "") && !identical(file, "<text>")) {
121-
# TODO: Handle absolute paths by using `wd`
122-
file <- normalizePath(file, mustWork = FALSE)
121+
if (!is_ark_uri(file)) {
122+
# TODO: Handle absolute paths by using `wd`
123+
file <- normalizePath(file, mustWork = FALSE)
124+
}
123125
content <- NULL
124126
} else if (!is.null(lines)) {
125127
file <- NULL

crates/ark/src/ui/events.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
//
66
//
77

8+
use std::str::FromStr;
9+
10+
use amalthea::comm::ui_comm::OpenEditorKind;
811
use amalthea::comm::ui_comm::OpenEditorParams;
912
use amalthea::comm::ui_comm::OpenWithSystemParams;
1013
use amalthea::comm::ui_comm::OpenWorkspaceParams;
@@ -63,11 +66,16 @@ pub unsafe extern "C-unwind" fn ps_ui_navigate_to_file(
6366
file: SEXP,
6467
line: SEXP,
6568
column: SEXP,
69+
uri: SEXP,
6670
) -> anyhow::Result<SEXP> {
71+
let kind: String = RObject::view(uri).try_into()?;
72+
let kind = OpenEditorKind::from_str(&kind)?;
73+
6774
let params = OpenEditorParams {
6875
file: RObject::view(file).try_into()?,
6976
line: RObject::view(line).try_into()?,
7077
column: RObject::view(column).try_into()?,
78+
kind,
7179
};
7280

7381
let event = UiFrontendEvent::OpenEditor(params);

0 commit comments

Comments
 (0)