Compare commits

...

9 Commits

Author SHA1 Message Date
Conrad Irwin
e2ae0125bd Fix g_ to go to last non-whitespace character
Use the new helpers for yss to do less buffer parsing.
2024-04-30 21:39:59 -06:00
hans
1e86d012a3 💄 2024-05-01 00:24:14 +08:00
hans
4adc1f16cb 💄 2024-05-01 00:23:13 +08:00
hans
6af5c650a2 adjust yss logic 2024-05-01 00:22:39 +08:00
hans
004e77e723 add support for yss operators 2024-04-30 23:02:05 +08:00
hans
6e9cfec24f Handle the case where there is an indent in front of the current line for the yss surrounds operation 2024-04-30 22:54:35 +08:00
Thorsten Ball
d743c19fe2 Add script to package Linux binary into archive (#11165)
Release Notes:

- N/A
2024-04-30 14:56:48 +02:00
Thorsten Ball
73d0600ad2 project: Set completion to undocumented if text empty (#11207)
I think the previous code was missing a `return` in there because it
always overwrote the `completion.documentation` field, even if the
`text.is_empty()` is true.

Release Notes:

- N/A
2024-04-30 14:56:22 +02:00
Stanislav Alekseev
f96cab286c Add avatar support for codeberg in git blame (#10991)
Release Notes:

- Added support for avatars in git blame for repositories hosted on
codeberg

<img width="1144" alt="Screenshot 2024-04-25 at 16 45 22"
src="https://github.com/zed-industries/zed/assets/43210583/d44770d8-44ea-4c6b-a1c0-ac2d1d49408f">

Questions:
- Should we move git stuff like `Commit`, `Author`, etc outside of
hosting-specific files (I don't think so, as other hostings can have
different stuff)
- Should we also add support for self hosted forgejo instances or should
it be a different PR?
2024-04-30 12:57:10 +02:00
17 changed files with 292 additions and 154 deletions

View File

@@ -260,15 +260,13 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
bundle-deb:
name: Create a *.deb Linux bundle
bundle-linux:
name: Create a Linux bundle
runs-on: ubuntu-22.04 # keep the version fixed to avoid libc and dynamic linked library issues
if: ${{ startsWith(github.ref, 'refs/tags/v') || contains(github.event.pull_request.labels.*.name, 'run-bundling') }}
needs: [linux_tests]
env:
ZED_CLIENT_CHECKSUM_SEED: ${{ secrets.ZED_CLIENT_CHECKSUM_SEED }}
DIGITALOCEAN_SPACES_ACCESS_KEY: ${{ secrets.DIGITALOCEAN_SPACES_ACCESS_KEY }}
DIGITALOCEAN_SPACES_SECRET_KEY: ${{ secrets.DIGITALOCEAN_SPACES_SECRET_KEY }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
@@ -312,19 +310,18 @@ jobs:
exit 1
fi
# TODO linux : Find a way to add licenses to the final bundle
# - name: Generate license file
# run: script/generate-licenses
- name: Generate license file
run: script/generate-licenses
- name: Create Linux *.deb bundle
- name: Create and upload Linux .tar.gz bundle
run: script/bundle-linux
- name: Upload app bundle to workflow run if main branch or specific label
- name: Upload Linux bundle to workflow run if main branch or specific label
uses: actions/upload-artifact@v4
if: ${{ github.ref == 'refs/heads/main' }} || contains(github.event.pull_request.labels.*.name, 'run-bundling') }}
with:
name: Zed_${{ github.event.pull_request.head.sha || github.sha }}.deb
path: target/release/*.deb
name: zed-${{ github.event.pull_request.head.sha || github.sha }}-x86_64-unknown-linux-gnu.tar.gz
path: zed-*.tar.gz
# TODO linux : make it stable enough to be uploaded as a release
# - uses: softprops/action-gh-release@v1

View File

@@ -94,7 +94,7 @@ jobs:
run: script/upload-nightly macos
bundle-deb:
name: Create a *.deb Linux bundle
name: Create a Linux *.tar.gz bundle
if: github.repository_owner == 'zed-industries'
runs-on: ubuntu-22.04 # keep the version fixed to avoid libc and dynamic linked library issues
needs: tests
@@ -125,12 +125,11 @@ jobs:
echo "Publishing version: ${version} on release channel nightly"
echo "nightly" > crates/zed/RELEASE_CHANNEL
# TODO linux : find a way to add licenses to the final bundle
# - name: Generate license file
# run: script/generate-licenses
- name: Generate license file
run: script/generate-licenses
- name: Create Linux *.deb bundle
- name: Create Linux .tar.gz bundle
run: script/bundle-linux
- name: Upload Zed Nightly
run: script/upload-nightly linux-deb
run: script/upload-nightly linux-targz

View File

@@ -3,7 +3,7 @@ use std::{ops::Range, sync::Arc};
use anyhow::Result;
use url::Url;
use util::{github, http::HttpClient};
use util::{codeberg, github, http::HttpClient};
use crate::Oid;
@@ -59,7 +59,7 @@ impl HostingProvider {
pub fn supports_avatars(&self) -> bool {
match self {
HostingProvider::Github => true,
HostingProvider::Github | HostingProvider::Codeberg => true,
_ => false,
}
}
@@ -71,24 +71,27 @@ impl HostingProvider {
commit: Oid,
client: Arc<dyn HttpClient>,
) -> Result<Option<Url>> {
match self {
Ok(match self {
HostingProvider::Github => {
let commit = commit.to_string();
let author =
github::fetch_github_commit_author(repo_owner, repo, &commit, &client).await?;
let url = if let Some(author) = author {
let mut url = Url::parse(&author.avatar_url)?;
url.set_query(Some("size=128"));
Some(url)
} else {
None
};
Ok(url)
github::fetch_github_commit_author(repo_owner, repo, &commit, &client)
.await?
.map(|author| -> Result<Url, url::ParseError> {
let mut url = Url::parse(&author.avatar_url)?;
url.set_query(Some("size=128"));
Ok(url)
})
.transpose()
}
HostingProvider::Codeberg => {
let commit = commit.to_string();
codeberg::fetch_codeberg_commit_author(repo_owner, repo, &commit, &client)
.await?
.map(|author| Url::parse(&author.avatar_url))
.transpose()
}
_ => Ok(None),
}
}?)
}
}

View File

@@ -5723,13 +5723,9 @@ impl Project {
return;
};
if response.text.is_empty() {
let mut completions = completions.write();
let completion = &mut completions[completion_index];
completion.documentation = Some(Documentation::Undocumented);
}
let documentation = if response.is_markdown {
let documentation = if response.text.is_empty() {
Documentation::Undocumented
} else if response.is_markdown {
Documentation::MultiLineMarkdown(
markdown::parse_markdown(&response.text, &language_registry, None).await,
)

View File

@@ -0,0 +1,78 @@
use crate::{git_author::GitAuthor, http::HttpClient};
use anyhow::{bail, Context, Result};
use futures::AsyncReadExt;
use isahc::{config::Configurable, AsyncBody, Request};
use serde::Deserialize;
use std::sync::Arc;
#[derive(Debug, Deserialize)]
struct CommitDetails {
commit: Commit,
author: Option<User>,
}
#[derive(Debug, Deserialize)]
struct Commit {
author: Author,
}
#[derive(Debug, Deserialize)]
struct Author {
name: String,
email: String,
date: String,
}
#[derive(Debug, Deserialize)]
struct User {
pub login: String,
pub id: u64,
pub avatar_url: String,
}
pub async fn fetch_codeberg_commit_author(
repo_owner: &str,
repo: &str,
commit: &str,
client: &Arc<dyn HttpClient>,
) -> Result<Option<GitAuthor>> {
let url = format!("https://codeberg.org/api/v1/repos/{repo_owner}/{repo}/git/commits/{commit}");
let mut request = Request::get(&url)
.redirect_policy(isahc::config::RedirectPolicy::Follow)
.header("Content-Type", "application/json");
if let Ok(codeberg_token) = std::env::var("CODEBERG_TOKEN") {
request = request.header("Authorization", format!("Bearer {}", codeberg_token));
}
let mut response = client
.send(request.body(AsyncBody::default())?)
.await
.with_context(|| format!("error fetching Codeberg commit details at {:?}", url))?;
let mut body = Vec::new();
response.body_mut().read_to_end(&mut body).await?;
if response.status().is_client_error() {
let text = String::from_utf8_lossy(body.as_slice());
bail!(
"status error {}, response: {text:?}",
response.status().as_u16()
);
}
let body_str = std::str::from_utf8(&body)?;
serde_json::from_str::<CommitDetails>(body_str)
.map(|codeberg_commit| {
if let Some(author) = codeberg_commit.author {
Some(GitAuthor {
avatar_url: author.avatar_url,
})
} else {
None
}
})
.context("deserializing Codeberg commit details failed")
}

View File

@@ -0,0 +1,5 @@
/// Represents the common denominator of most git hosting authors
#[derive(Debug)]
pub struct GitAuthor {
pub avatar_url: String,
}

View File

@@ -1,4 +1,4 @@
use crate::http::HttpClient;
use crate::{git_author::GitAuthor, http::HttpClient};
use anyhow::{anyhow, bail, Context, Result};
use futures::AsyncReadExt;
use isahc::{config::Configurable, AsyncBody, Request};
@@ -49,19 +49,12 @@ struct User {
pub avatar_url: String,
}
#[derive(Debug)]
pub struct GitHubAuthor {
pub id: u64,
pub email: String,
pub avatar_url: String,
}
pub async fn fetch_github_commit_author(
repo_owner: &str,
repo: &str,
commit: &str,
client: &Arc<dyn HttpClient>,
) -> Result<Option<GitHubAuthor>> {
) -> Result<Option<GitAuthor>> {
let url = format!("https://api.github.com/repos/{repo_owner}/{repo}/commits/{commit}");
let mut request = Request::get(&url)
@@ -93,10 +86,8 @@ pub async fn fetch_github_commit_author(
serde_json::from_str::<CommitDetails>(body_str)
.map(|github_commit| {
if let Some(author) = github_commit.author {
Some(GitHubAuthor {
id: author.id,
Some(GitAuthor {
avatar_url: author.avatar_url,
email: github_commit.commit.author.email,
})
} else {
None

View File

@@ -1,5 +1,7 @@
pub mod arc_cow;
pub mod codeberg;
pub mod fs;
mod git_author;
pub mod github;
pub mod http;
pub mod paths;

View File

@@ -447,6 +447,8 @@ pub(crate) fn motion(motion: Motion, cx: &mut WindowContext) {
vim.clear_operator(cx);
if let Some(operator) = waiting_operator {
vim.push_operator(operator, cx);
dbg!(count);
vim.update_state(|state| state.pre_count = count)
}
});
}
@@ -755,7 +757,7 @@ impl Motion {
},
NextLineStart => (next_line_start(map, point, times), SelectionGoal::None),
StartOfLineDownward => (next_line_start(map, point, times - 1), SelectionGoal::None),
EndOfLineDownward => (next_line_end(map, point, times), SelectionGoal::None),
EndOfLineDownward => (last_non_whitespace(map, point, times), SelectionGoal::None),
GoToColumn => (go_to_column(map, point, times), SelectionGoal::None),
WindowTop => window_top(map, point, &text_layout_details, times - 1),
WindowMiddle => window_middle(map, point, &text_layout_details),
@@ -1422,6 +1424,28 @@ pub(crate) fn first_non_whitespace(
start_offset.to_display_point(map)
}
pub(crate) fn last_non_whitespace(
map: &DisplaySnapshot,
from: DisplayPoint,
count: usize,
) -> DisplayPoint {
let mut end_of_line = end_of_line(map, false, from, count).to_offset(map, Bias::Left);
let scope = map.buffer_snapshot.language_scope_at(from.to_point(map));
dbg!(end_of_line);
for (ch, offset) in map.reverse_buffer_chars_at(end_of_line) {
if ch == '\n' {
break;
}
end_of_line = offset;
dbg!(ch, offset);
if char_kind(&scope, ch) != CharKind::Whitespace || ch == '\n' {
break;
}
}
end_of_line.to_display_point(map)
}
pub(crate) fn start_of_line(
map: &DisplaySnapshot,
display_lines: bool,
@@ -1899,6 +1923,16 @@ mod test {
cx.assert_shared_state("one\n ˇtwo\nthree").await;
}
#[gpui::test]
async fn test_end_of_line_downward(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;
cx.set_shared_state("ˇ one \n two \nthree").await;
cx.simulate_shared_keystrokes(["g", "_"]).await;
cx.assert_shared_state(" onˇe \n two \nthree").await;
cx.simulate_shared_keystrokes(["2", "g", "_"]).await;
cx.assert_shared_state(" one \n twˇo \nthree").await;
}
#[gpui::test]
async fn test_window_top(cx: &mut gpui::TestAppContext) {
let mut cx = NeovimBackedTestContext::new(cx).await;

View File

@@ -1,4 +1,9 @@
use crate::{motion::Motion, object::Object, state::Mode, Vim};
use crate::{
motion::{self, Motion},
object::Object,
state::Mode,
Vim,
};
use editor::{movement, scroll::Autoscroll, Bias};
use gpui::WindowContext;
use language::BracketPair;
@@ -23,6 +28,7 @@ impl<'de> Deserialize<'de> for SurroundsType {
pub fn add_surrounds(text: Arc<str>, target: SurroundsType, cx: &mut WindowContext) {
Vim::update(cx, |vim, cx| {
vim.stop_recording();
let count = vim.take_count(cx);
vim.update_active_editor(cx, |_, editor, cx| {
let text_layout_details = editor.text_layout_details(cx);
editor.transact(cx, |editor, cx| {
@@ -52,22 +58,26 @@ pub fn add_surrounds(text: Arc<str>, target: SurroundsType, cx: &mut WindowConte
.range(
&display_map,
selection.clone(),
Some(1),
count,
true,
&text_layout_details,
)
.map(|mut range| {
// The Motion::CurrentLine operation will contain the newline of the current line,
// so we need to deal with this edge case
// The Motion::CurrentLine operation will contain the newline of the current line and leading/trailing whitespace
if let Motion::CurrentLine = motion {
let offset = range.end.to_offset(&display_map, Bias::Left);
if let Some((last_ch, _)) =
display_map.reverse_buffer_chars_at(offset).next()
{
if last_ch == '\n' {
range.end = movement::left(&display_map, range.end);
}
}
range.start = motion::first_non_whitespace(
&display_map,
false,
range.start,
);
range.end = movement::saturating_right(
&display_map,
motion::last_non_whitespace(
&display_map,
movement::left(&display_map, range.end),
1,
),
);
}
range
});
@@ -627,6 +637,30 @@ mod test {
the lazy dog."},
Mode::Normal,
);
cx.set_state(
indoc! {"
The quˇick brown•
fox jumps over
the lazy dog."},
Mode::Normal,
);
cx.simulate_keystrokes(["y", "s", "s", "{"]);
cx.assert_state(
indoc! {"
ˇ{ The quick brown }•
fox jumps over
the lazy dog."},
Mode::Normal,
);
cx.simulate_keystrokes(["2", "y", "s", "s", ")"]);
cx.assert_state(
indoc! {"
ˇ({ The quick brown }•
fox jumps over)
the lazy dog."},
Mode::Normal,
);
}
#[gpui::test]

View File

@@ -526,7 +526,7 @@ impl Vim {
| Operator::ChangeSurrounds { .. }
| Operator::DeleteSurrounds
) {
self.clear_operator(cx);
self.update_state(|state| state.operator_stack.clear());
};
self.update_state(|state| state.operator_stack.push(operator));
self.sync_vim_settings(cx);

View File

@@ -0,0 +1,8 @@
{"Put":{"state":"ˇ one \n two \nthree"}}
{"Key":"g"}
{"Key":"_"}
{"Get":{"state":" onˇe \n two \nthree","mode":"Normal"}}
{"Key":"2"}
{"Key":"g"}
{"Key":"_"}
{"Get":{"state":" one \n twˇo \nthree","mode":"Normal"}}

View File

@@ -0,0 +1,13 @@
[Desktop Entry]
Version=1.0
Type=Application
Name=Zed
GenericName=Text Editor
Comment=A high-performance, multiplayer code editor.
TryExec=zed
StartupNotify=true
Exec=zed
Icon=zed
Categories=TextEditor;Development;IDE;
Keywords=zed;
MimeType=text/plain;

View File

@@ -2,32 +2,20 @@
set -euxo pipefail
build_flag="--release"
target_dir="release"
bundle_name=""
zed_crate="zed"
# Function for displaying help info
help_info() {
echo "
Usage: ${0##*/} [options] [bundle_name]
Build the application bundle for Linux.
Usage: ${0##*/} [options]
Build a release .tar.gz for Linux.
Options:
-d Compile in debug mode
-h Display this help and exit
-h Display this help and exit.
"
}
while getopts 'dh' flag
while getopts 'h' flag
do
case "${flag}" in
d)
export CARGO_INCREMENTAL=true
export CARGO_BUNDLE_SKIP_BUILD=true
build_flag="";
target_dir="debug"
;;
h)
help_info
exit 0
@@ -35,68 +23,54 @@ do
esac
done
shift $((OPTIND-1))
if [[ $# -gt 0 ]]; then
if [ "$1" ]; then
bundle_name=$1
fi
fi
export ZED_BUNDLE=true
cargo_bundle_version=$(cargo -q bundle --help 2>&1 | head -n 1 || echo "")
if [ "$cargo_bundle_version" != "cargo-bundle v0.6.0-zed" ]; then
cargo install cargo-bundle --git https://github.com/zed-industries/cargo-bundle.git --branch zed-deploy
channel=$(<crates/zed/RELEASE_CHANNEL)
version="$(cargo metadata --no-deps --manifest-path crates/zed/Cargo.toml --offline --format-version=1 | jq -r '.packages | map(select(.name == "zed"))[0].version')"
commit=$(git rev-parse HEAD | cut -c 1-7)
version_info=$(rustc --version --verbose)
host_line=$(echo "$version_info" | grep host)
target_triple=${host_line#*: }
# Build binary in release mode
cargo build --release --target "${target_triple}" --package zed
# Strip the binary of all debug symbols
# Later, we probably want to do something like this: https://github.com/GabrielMajeri/separate-symbols
strip "target/${target_triple}/release/Zed"
# Move everything that should end up in the final package
# into a temp directory.
temp_dir=$(mktemp -d)
# Binary
mkdir "${temp_dir}/bin"
cp "target/${target_triple}/release/Zed" "${temp_dir}/bin/zed"
# Icons
mkdir -p "${temp_dir}/share/icons/hicolor/512x512/apps"
cp "crates/zed/resources/app-icon-nightly.png" "${temp_dir}/share/icons/hicolor/512x512/apps/zed.png"
mkdir -p "${temp_dir}/share/icons/hicolor/1024x1024/apps"
cp "crates/zed/resources/app-icon-nightly@2x.png" "${temp_dir}/share/icons/hicolor/1024x1024/apps/zed.png"
# .desktop
mkdir -p "${temp_dir}/share/applications"
cp "crates/zed/resources/zed.desktop" "${temp_dir}/share/applications/zed.desktop"
# Licenses
cp "assets/licenses.md" "${temp_dir}/licenses.md"
# Create archive out of everything that's in the temp directory
if [[ "$channel" == "nightly" ]]; then
archive="zed-${channel}-${target_triple}.tar.gz"
elif [[ "$channel" == "dev" ]]; then
archive="zed-${channel}-${commit}-${target_triple}.tar.gz"
else
archive="zed-${version}-${target_triple}.tar.gz"
fi
echo "Compiling zed binaries"
cargo build ${build_flag} --package ${zed_crate} --package cli
echo "Creating application bundle"
pushd crates/${zed_crate}
channel=$(<RELEASE_CHANNEL)
cp Cargo.toml Cargo.toml.backup
sed \
-i.backup -e \
"s/package.metadata.bundle-${channel}/package.metadata.bundle/" \
Cargo.toml
# TODO linux `zed_cli` does not get into this bundle despite being built
bundle_path=$(cargo bundle ${build_flag} --select-workspace-root | xargs)
mv Cargo.toml.backup Cargo.toml
popd
# For nightly, cut off the version out of the bundle name that `cargo bundle` always adds.
if [ "$channel" == "nightly" ]; then
version="$(cargo metadata --no-deps --manifest-path crates/zed/Cargo.toml --offline --format-version=1 | jq -r '.packages | map(select(.name == "zed"))[0].version')"
version_less_bundle_path=$(echo "$bundle_path" | sed "s/_$version//")
mv "$bundle_path" "$version_less_bundle_path"
bundle_path="$version_less_bundle_path"
fi
# TODO linux
# Other Linux systems will need a different set of manipulations + a way to know which ones to do.
# If bundle_name is not set or empty, use the basename of $bundle_path
if [ -z "${bundle_name}" ]; then
bundle_name=$(basename "${bundle_path}")
fi
# If bundle_name doesn't end in .deb, append it
if [[ "$bundle_name" != *.deb ]]; then
bundle_name="$bundle_name.deb"
fi
pushd target/
rm -rf bundle/ 2>/dev/null || true
dpkg-deb -x "${bundle_path}" bundle/
dpkg-deb --control "${bundle_path}" bundle/DEBIAN
mkdir -p bundle/usr/local/bin/
mv bundle/usr/bin/Zed "bundle/usr/local/bin/zed-$channel"
cp "${target_dir}/cli" "bundle/usr/local/bin/cli-$channel"
ln -s "/usr/local/bin/cli-$channel" "bundle/usr/local/bin/zed"
rm -rf bundle/usr/bin/
dpkg-deb -b bundle/ "${target_dir}/${bundle_name}"
bundle_path="${PWD}/${target_dir}/${bundle_name}"
popd
echo "Bundled ${bundle_path}"
rm -rf "${archive}"
tar -czvf $archive -C ${temp_dir} .

View File

@@ -19,9 +19,12 @@ echo -e "# ###### CODE LICENSES ######\n" >> $OUTPUT_FILE
echo "Generating cargo licenses"
cargo about generate --fail -c script/licenses/zed-licenses.toml script/licenses/template.hbs.md >> $OUTPUT_FILE
sed -i '' 's/&quot;/"/g' $OUTPUT_FILE
sed -i '' 's/&#x27;/'\''/g' $OUTPUT_FILE # The ` '\'' ` thing ends the string, appends a single quote, and re-opens the string
sed -i '' 's/&#x3D;/=/g' $OUTPUT_FILE
sed -i '' 's/&#x60;/`/g' $OUTPUT_FILE
sed -i '' 's/&lt;/</g' $OUTPUT_FILE
sed -i '' 's/&gt;/>/g' $OUTPUT_FILE
sed -i.bak 's/&quot;/"/g' $OUTPUT_FILE
sed -i.bak 's/&#x27;/'\''/g' $OUTPUT_FILE # The ` '\'' ` thing ends the string, appends a single quote, and re-opens the string
sed -i.bak 's/&#x3D;/=/g' $OUTPUT_FILE
sed -i.bak 's/&#x60;/`/g' $OUTPUT_FILE
sed -i.bak 's/&lt;/</g' $OUTPUT_FILE
sed -i.bak 's/&gt;/>/g' $OUTPUT_FILE
rm -rf "${OUTPUT_FILE}.bak"

1
script/install.sh Normal file
View File

@@ -0,0 +1 @@
#!/bin/sh

View File

@@ -4,7 +4,7 @@
bash -euo pipefail
source script/lib/blob-store.sh
allowed_targets=("linux-deb" "macos")
allowed_targets=("linux-targz" "macos")
is_allowed_target() {
for val in "${allowed_targets[@]}"; do
if [[ "$1" == "$val" ]]; then
@@ -40,11 +40,11 @@ case "$target" in
upload_to_blob_store $bucket_name "target/release/Zed.dmg" "nightly/Zed.dmg"
upload_to_blob_store $bucket_name "target/latest-sha" "nightly/latest-sha"
;;
linux-deb)
find target/release -type f -name "*.deb" -print0 | while IFS= read -r -d '' bundle_file; do
linux-targz)
find . -type f -name "zed-*.tar.gz" -print0 | while IFS= read -r -d '' bundle_file; do
upload_to_blob_store $bucket_name "$bundle_file" "nightly/$(basename "$bundle_file")"
done
upload_to_blob_store $bucket_name "target/latest-sha" "nightly/latest-sha-linux-deb"
upload_to_blob_store $bucket_name "target/latest-sha" "nightly/latest-sha-linux-targz"
;;
*)
echo "Error: Unknown target '$target'"