GtkSourceView bindings for Rust.
MIT
sourceview binding for Rust
License: MIT License
GtkSourceView bindings for Rust.
MIT
I'm currently trying to use this crate in a project that needs heavy-duty source code editing. Part of that is a basic auto-complete implementation. It needs to be a bit more context-sensitive than the current words-based implementation, but not by much. I've decided what algorithms I want to use to do the actual completion, but getting the library to call my code to do the completion and present it to the user seems to currently be impossible. As such, this is a feature request to add the necessary API hooks to make that happen.
While only adding the necessary traits as described in the linked issue is one way of adding this support, ideally, a subclass or interface implementation would not be needed to use these features, as those techniques are cumbersome with GObject in general, but, it would seem, especially so in Rust since one must not only deal with GObject (which is as cumbersome as any C API), but must also deal with the intricacies of the binding at the same time.
As such, I propose a different interface where there is a simple trait that the user can implement, and then pass a dyn
object to the Rust bindings to act in a similar way as the GObject interface, but where it is significantly easier to use because Rust has built-in support for implementing traits. This could be implemented via adding those traits, then creating a Rust implementation that has a Box<dyn TheTraitThatIJustMentioned>
as a member.
While I am willing to attempt this addition myself and PR it, I don't think that I'm the best person to do that. I'm currently new to Rust, GTK/GObject, and these bindings (I've never even used Rust's FFI support), so if I were to do it it would likely have many errors, if I could get it working at all. I do have significant experience with other tools though, such as C without GObject, C++, and some minimal assembly (I once had to write some assembly to call C functions and be called as a C function, without the aid of a compiler, so I am familiar with how FFI probably works despite the fact that I haven't looked into it.).
The functions sourceview::FileLoaderExt::load_async
and sourceview::FileSaverExt::save_async
are yet to be unimplemented, which means FileLoader
and FileSaver
objects are of little use. I would like to be able to use them in a project, and would have a go myself though still a relative Rust newb - are there any non-straightforward design issues holding this up, or should I give it a go?
Is there any example application showing to use sourceview?
With gtk 0.5.0 and sourceview 0.5.0, all goes fine, until I try to use
gtk::ResponseType::Other(0)
which is only available from gtk 0.6.0.
So I change to gtk 0.6.0, sourceview ^0, and now get
error[E0433]: failed to resolve: could not find 'FileLoader' in 'sourceview'
Changing to sourceview to 0.6.0 makes no difference.
The doco shows 'FileLoader' as features v3_14
, so I try adding that to sourceview, which gives me
error: failed to select a version for 'sourceview'. ... required by package 'foo v0.1.0 (/.../foo)' versions that meet the requirements '= 0.6.0' are: 0.6.0 the package 'foo' depends on 'sourceview', with features: 'v3_14' but 'sourceview' does not have these features.
This is a known bug, which I reported recently (issue #92, now closed).
To work round the v3_14 problem, I clone sourceview branch 0.6.0, fix the 'v3_14' bug, and point cargo at my local copy. Now the error is:
Updating git repository 'https://github.com/gtk-rs/pango' error: failed to select a version for 'gdk-pixbuf-sys'. ... required by package 'sourceview v0.6.0 (/.../sourceview)' ... which is depended on by 'foo' v0.1.0 (/.../foo)' versions that meet the requirements '*' are: 0.8.0 the package 'gdk-pixbuf-sys' links to the native library 'gdk_pixbuf', but it conflicts with a previous package which links to 'gdk_pixbuf' as well: package 'gdk-pixbuf-sys v0.8.0' ... which is depended on by 'gtk v0.6.0' ... which is depended on by 'foo v0.1.0 (/.../foo)' failed to select a version for 'gdk-pixbuf-sys' which could resolve this conflict
I'm stumped by that, as I am still somewhat of a noob with Cargo/git versioning, and would be grateful for some guidance on a work-round that works. :)
I want set_accepts_tab() to move keyboard focus between Views with the tab key. Now, View have set_accepts_tab() but there is no implementation.
let buff = Buffer::new::<gtk::TextTagTable>(None);
let view = View::new_with_buffer(&buff);
view.set_accepts_tab(false); // not working!!
Is there any plans to implement it?
For now it's missing.
Option to add in Gir.toml
(besides the macros in rt.rs
): generate_safety_asserts=true
⋊> ~/P/u/systemd-manager on rewrite-deps ↑ cargo build -j8 10:36:58
Compiling void v1.0.2
Compiling gio v0.3.0
Compiling toml v0.2.1
Compiling unicode-xid v0.0.4
Compiling horrorshow v0.6.2
Compiling cairo-rs v0.3.0
Compiling lazy_static v0.2.11
Compiling libc v0.2.34
Compiling error-chain v0.10.0
Compiling gdk-pixbuf v0.3.0
Compiling cc v1.0.3
Compiling quote v0.3.15
Compiling sourceview v0.3.0
Compiling bitflags v1.0.1
Compiling cfg-if v0.1.2
Compiling c_vec v1.2.1
Compiling gtk v0.3.0
Compiling nodrop v0.1.12
Compiling pkg-config v0.3.9
Compiling gdk v0.7.0
Compiling rustc-demangle v0.1.5
Compiling unreachable v0.1.1
Compiling synom v0.11.3
Compiling quickersort v3.0.0
Compiling syn v0.11.11
Compiling backtrace-sys v0.1.16
Compiling gtk-sys v0.5.0
Compiling pango-sys v0.5.0
Compiling gio-sys v0.5.0
Compiling gobject-sys v0.5.0
Compiling gdk-pixbuf-sys v0.5.0
Compiling atk-sys v0.5.0
Compiling metadeps v1.1.2
Compiling gdk-sys v0.5.0
Compiling cairo-sys-rs v0.5.0
Compiling gtk-source-sys v0.5.0
Compiling glib-sys v0.5.0
Compiling libdbus-sys v0.1.2
Compiling dbus v0.6.1
Compiling synstructure v0.6.1
Compiling failure_derive v0.1.1
Compiling glib v0.4.0
Compiling backtrace v0.3.4
Compiling failure v0.1.1
Compiling pango v0.3.0
error[E0308]: mismatched types
--> /home/brain/.cargo/registry/src/github.com-1ecc6299db9ec823/sourceview-0.3.0/src/auto/search_context.rs:173:103
|
173 | let _ = ffi::gtk_source_search_context_backward_finish(_source_object as *mut _, res, &mut match_start, &mut match_end, &mut error);
| ^^^^^^^^^^^^^^^^ expected struct `gtk_ffi::GtkTextIter`, found struct `gtk::TextIter`
|
= note: expected type `*mut gtk_ffi::GtkTextIter`
found type `&mut gtk::TextIter`
error[E0308]: mismatched types
--> /home/brain/.cargo/registry/src/github.com-1ecc6299db9ec823/sourceview-0.3.0/src/auto/search_context.rs:173:121
|
173 | let _ = ffi::gtk_source_search_context_backward_finish(_source_object as *mut _, res, &mut match_start, &mut match_end, &mut error);
| ^^^^^^^^^^^^^^ expected struct `gtk_ffi::GtkTextIter`, found struct `gtk::TextIter`
|
= note: expected type `*mut gtk_ffi::GtkTextIter`
found type `&mut gtk::TextIter`
error[E0277]: the trait bound `gtk::TextIter: glib::translate::Ptr` is not satisfied
--> /home/brain/.cargo/registry/src/github.com-1ecc6299db9ec823/sourceview-0.3.0/src/auto/search_context.rs:174:55
|
174 | let result = if error.is_null() { Ok((from_glib_none(match_start), from_glib_none(match_end))) } else { Err(from_glib_full(error)) };
| ^^^^^^^^^^^^^^ the trait `glib::translate::Ptr` is not implemented for `gtk::TextIter`
|
= note: required by `glib::translate::from_glib_none`
error[E0277]: the trait bound `gtk::TextIter: glib::translate::Ptr` is not satisfied
--> /home/brain/.cargo/registry/src/github.com-1ecc6299db9ec823/sourceview-0.3.0/src/auto/search_context.rs:174:84
|
174 | let result = if error.is_null() { Ok((from_glib_none(match_start), from_glib_none(match_end))) } else { Err(from_glib_full(error)) };
| ^^^^^^^^^^^^^^ the trait `glib::translate::Ptr` is not implemented for `gtk::TextIter`
|
= note: required by `glib::translate::from_glib_none`
error[E0277]: the trait bound `gtk::TextIter: glib::translate::FromGlibPtrNone<gtk::TextIter>` is not satisfied
--> /home/brain/.cargo/registry/src/github.com-1ecc6299db9ec823/sourceview-0.3.0/src/auto/search_context.rs:174:55
|
174 | let result = if error.is_null() { Ok((from_glib_none(match_start), from_glib_none(match_end))) } else { Err(from_glib_full(error)) };
| ^^^^^^^^^^^^^^ the trait `glib::translate::FromGlibPtrNone<gtk::TextIter>` is not implemented for `gtk::TextIter`
|
= help: the following implementations were found:
<gtk::TextIter as glib::translate::FromGlibPtrNone<*mut gtk_ffi::GtkTextIter>>
= note: required by `glib::translate::from_glib_none`
error[E0277]: the trait bound `gtk::TextIter: glib::translate::FromGlibPtrNone<gtk::TextIter>` is not satisfied
--> /home/brain/.cargo/registry/src/github.com-1ecc6299db9ec823/sourceview-0.3.0/src/auto/search_context.rs:174:84
|
174 | let result = if error.is_null() { Ok((from_glib_none(match_start), from_glib_none(match_end))) } else { Err(from_glib_full(error)) };
| ^^^^^^^^^^^^^^ the trait `glib::translate::FromGlibPtrNone<gtk::TextIter>` is not implemented for `gtk::TextIter`
|
= help: the following implementations were found:
<gtk::TextIter as glib::translate::FromGlibPtrNone<*mut gtk_ffi::GtkTextIter>>
= note: required by `glib::translate::from_glib_none`
error[E0308]: mismatched types
--> /home/brain/.cargo/registry/src/github.com-1ecc6299db9ec823/sourceview-0.3.0/src/auto/search_context.rs:223:102
|
223 | let _ = ffi::gtk_source_search_context_forward_finish(_source_object as *mut _, res, &mut match_start, &mut match_end, &mut error);
| ^^^^^^^^^^^^^^^^ expected struct `gtk_ffi::GtkTextIter`, found struct `gtk::TextIter`
|
= note: expected type `*mut gtk_ffi::GtkTextIter`
found type `&mut gtk::TextIter`
error[E0308]: mismatched types
--> /home/brain/.cargo/registry/src/github.com-1ecc6299db9ec823/sourceview-0.3.0/src/auto/search_context.rs:223:120
|
223 | let _ = ffi::gtk_source_search_context_forward_finish(_source_object as *mut _, res, &mut match_start, &mut match_end, &mut error);
| ^^^^^^^^^^^^^^ expected struct `gtk_ffi::GtkTextIter`, found struct `gtk::TextIter`
|
= note: expected type `*mut gtk_ffi::GtkTextIter`
found type `&mut gtk::TextIter`
error[E0277]: the trait bound `gtk::TextIter: glib::translate::Ptr` is not satisfied
--> /home/brain/.cargo/registry/src/github.com-1ecc6299db9ec823/sourceview-0.3.0/src/auto/search_context.rs:224:55
|
224 | let result = if error.is_null() { Ok((from_glib_none(match_start), from_glib_none(match_end))) } else { Err(from_glib_full(error)) };
| ^^^^^^^^^^^^^^ the trait `glib::translate::Ptr` is not implemented for `gtk::TextIter`
|
= note: required by `glib::translate::from_glib_none`
error[E0277]: the trait bound `gtk::TextIter: glib::translate::Ptr` is not satisfied
--> /home/brain/.cargo/registry/src/github.com-1ecc6299db9ec823/sourceview-0.3.0/src/auto/search_context.rs:224:84
|
224 | let result = if error.is_null() { Ok((from_glib_none(match_start), from_glib_none(match_end))) } else { Err(from_glib_full(error)) };
| ^^^^^^^^^^^^^^ the trait `glib::translate::Ptr` is not implemented for `gtk::TextIter`
|
= note: required by `glib::translate::from_glib_none`
error[E0277]: the trait bound `gtk::TextIter: glib::translate::FromGlibPtrNone<gtk::TextIter>` is not satisfied
--> /home/brain/.cargo/registry/src/github.com-1ecc6299db9ec823/sourceview-0.3.0/src/auto/search_context.rs:224:55
|
224 | let result = if error.is_null() { Ok((from_glib_none(match_start), from_glib_none(match_end))) } else { Err(from_glib_full(error)) };
| ^^^^^^^^^^^^^^ the trait `glib::translate::FromGlibPtrNone<gtk::TextIter>` is not implemented for `gtk::TextIter`
|
= help: the following implementations were found:
<gtk::TextIter as glib::translate::FromGlibPtrNone<*mut gtk_ffi::GtkTextIter>>
= note: required by `glib::translate::from_glib_none`
error[E0277]: the trait bound `gtk::TextIter: glib::translate::FromGlibPtrNone<gtk::TextIter>` is not satisfied
--> /home/brain/.cargo/registry/src/github.com-1ecc6299db9ec823/sourceview-0.3.0/src/auto/search_context.rs:224:84
|
224 | let result = if error.is_null() { Ok((from_glib_none(match_start), from_glib_none(match_end))) } else { Err(from_glib_full(error)) };
| ^^^^^^^^^^^^^^ the trait `glib::translate::FromGlibPtrNone<gtk::TextIter>` is not implemented for `gtk::TextIter`
|
= help: the following implementations were found:
<gtk::TextIter as glib::translate::FromGlibPtrNone<*mut gtk_ffi::GtkTextIter>>
= note: required by `glib::translate::from_glib_none`
error: aborting due to 12 previous errors
error: Could not compile `sourceview`.
To learn more, run the command again with --verbose.
It might be that I do something wrong, but...
I'm not seeing any methods for creating a Language
, so it's currently impossible to use syntax highlighting within a SourceBuffer.
Is this ready to be used? If so, how would I go about using it?
For now, only the crate
branch has a complete one.
Right now, the only way to use a custom language for syntax highlighting is to install the .lang file inside specific folders or add a folder that contains it to the search path.
It would be very nice to add the ability to load a custom language syntax from a &str, which would allow to embed the file inside the executable using the include_str!() macro.
MIT requires text license to be present along with source and gtk-source archive on crates.io doesn't have it.
From the gnome developper doc the Source View Object inherits from scrollable.
The TextView type implements ScrollableExt, this is not the case for sourceview::View
The doco for sourceview crate at http://gtk-rs.org/docs/sourceview/struct.File.html
says I need feature v3_14
to enable use of sourceview::File, so I changed my Cargo.toml [dependencies]
from
sourceview = "0.5.0"
to
sourceview = { version = "0.5.0", features = ["v3_14"] }
and now get errors saying
failed to select a version for 'sourceview'. ... required by package 'foo v0.1.0 (/projects/foo)' versions that meet the requirements '^0.5.0' are: 0.5.0 the package 'foo' depends on 'sourceview', with features: 'v3_14' but 'sourceview' does not have these features.
The sourceview manifest is presumably missing a line like:
v3_14 = ["v3_12", "gtk-source-sys/v3_14"]
Is there a temporary work-around I can do for this?
Yet another crate reached 1.0, would be nice if you could upgrade.
The latter is still GTK3 based
I have a sourceview::Buffer which is then used inside of a soureview::View
. Getting the text inside the buffer seems impossible at the current version. The TextBufferExt is implemented by the sourceview::Buffer, with a get_text
method.
This is the signature of the method
fn get_text(
&self,
start: &TextIter,
end: &TextIter,
include_hidden_chars: bool
) -> Option<GString>
but it needs TexIter as argument, which can not be instantiated, nor derived from numbers or anything.
I just need to get all the text in the buffer starting from 0 to end.
This seems impossible to do it.
In the main crate of gtk-rs, most widgets have a builder struct such as:
let builder = gtk::TextViewBuilder::new();
/* ... setup */
let text_view = builder.build();
which are missing in the sourceview crate alltogether. This is horribly inconsistent. The builders appear (to me) to be auto-generated, would it be possible to provide such structs in the next release?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.