Skip to content

Commit c1dcaba

Browse files
committed
Fix forgejo links
Fixes #4688 (comment)
1 parent 67bca89 commit c1dcaba

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,7 @@
146146
- Fixed a bug where the compiler would suggest a discouraged project name as an
147147
alternative to the reserved `gleam` name.
148148
([Giacomo Cavalieri](https://github.com/giacomocavalieri))
149+
150+
- Fixed a bug where Forgejo source URLs in the HTML documentation could be
151+
incorrectly structured.
152+
([Louis Pilfold](https://github.com/lpil))

compiler-core/src/docs/source_links.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl SourceLinker {
7373
let cleaned_host = string_host.trim_end_matches('/');
7474
Some((
7575
format!("{cleaned_host}/{user}/{repo}/src/tag/{tag}/{path_in_repo}#L",),
76-
"-".into(),
76+
"-L".into(),
7777
))
7878
}
7979
Repository::Custom { .. } => None,
@@ -85,6 +85,7 @@ impl SourceLinker {
8585
url_pattern,
8686
}
8787
}
88+
8889
pub fn url(&self, span: SrcSpan) -> String {
8990
match &self.url_pattern {
9091
Some((base, line_sep)) => {

compiler-core/src/docs/tests.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,3 +1190,47 @@ pub fn aaaaaaaaaaaaaaaaaaaaaaaaaaaa() -> aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa {
11901190
NONE
11911191
);
11921192
}
1193+
1194+
#[test]
1195+
fn forgejo_single_line_definition() {
1196+
let mut config = PackageConfig::default();
1197+
let repo = Repository::Forgejo {
1198+
host: "https://code.example.org/".parse::<Uri>().unwrap(),
1199+
user: "wibble".into(),
1200+
repo: "wobble".into(),
1201+
path: None,
1202+
tag_prefix: None,
1203+
};
1204+
1205+
config.name = EcoString::from("test_project_name");
1206+
config.repository = Some(repo);
1207+
1208+
let modules = vec![("app.gleam", "pub type Wibble = Int")];
1209+
let html = compile(config, modules);
1210+
1211+
assert!(
1212+
html.contains("https://code.example.org/wibble/wobble/src/tag/v0.1.0/src/app.gleam#L1")
1213+
);
1214+
}
1215+
1216+
#[test]
1217+
fn forgejo_multiple_line_definition() {
1218+
let mut config = PackageConfig::default();
1219+
let repo = Repository::Forgejo {
1220+
host: "https://code.example.org/".parse::<Uri>().unwrap(),
1221+
user: "wibble".into(),
1222+
repo: "wobble".into(),
1223+
path: None,
1224+
tag_prefix: None,
1225+
};
1226+
1227+
config.name = EcoString::from("test_project_name");
1228+
config.repository = Some(repo);
1229+
1230+
let modules = vec![("app.gleam", "pub type Wibble \n\n= Int")];
1231+
let html = compile(config, modules);
1232+
1233+
assert!(
1234+
html.contains("https://code.example.org/wibble/wobble/src/tag/v0.1.0/src/app.gleam#L1-L3")
1235+
);
1236+
}

0 commit comments

Comments
 (0)