-
Notifications
You must be signed in to change notification settings - Fork 162
Create a client for Sublime Text #363
Comments
😊
cquery implements rainbow semantic highlighting https://github.com/cquery-project/cquery/blob/master/src/message_handler.cc EmitSemanticHighlighting Regex based syntax highlighting is still good because files in editing may not compile and compilation has a high latency. There are some diff algorithm based heuristics to make cross references when the document differs from its indexed version.
These LSP requests are most useful
There are also some fancy usage and some cquery cross reference extensions (e.g. $cquery/dervided), see https://github.com/cquery-project/cquery/wiki/FAQ#definitions
Snippets are supported via completion. The responses to
Supported. BTW,
A
Comments are indexed by default. If the client supports it, textDocument/hover can display comments. There is also a documentation field in LSP
I'd like to see Debug Protocol attracts more attention.
A dedicated plugin may still be needed for some cquery extensions. See those https://github.com/cquery-project/emacs-cquery/ is a plugin that leverages lsp-mode (which is a generic LSP client), because semantic highlighting, cross reference extentions ($cquery/derived $cquery/base ...) are not in standard LSP.
Macros RTags supports indexing of function calls from one-level macro expansions. See #331 Dependency // a.h
extern int foo;
// a.cc
#include "a.h"
int foo;
// b.cc
extern int foo; Out-of-band changes to RTags uses a C/S model while cquery is started by the editor and they communicate through stdin/stdout. Pipe (Emacs lsp-mode, LanguageClient-neovim), or Unix socket (VSCode). Symbol information
Templates How well does RTags handle template specialization? See #353 RTags traverses the translation unit top-down while cquery uses higher level clang_indexTranslationUnit through declaration/reference callbacks. There is some limitation: // U is not indexed because it is not referenced
template<class T, class U>
void f(T a) {} No way to retrieve the location of typedef int int32_t;
enum E : int32_t { E0, E1 }; RTags has typedef int int32_t;
enum E : int32_t {
E0,
E1,
};
{
"id": 2,
"usr": 8563738222191832000,
"short_name": "E1",
"detailed_name": "E::E1",
"kind": 15,
"storage": 0,
"hover": "E::E1 = 1",
"declarations": [],
"definition_spelling": "5:3-5:5",
"definition_extent": "5:3-5:5",
"variable_type": 1,
"declaring_type": 1,
"uses": []
}
I think RTags does not do well in terms of query performance. Andersbakken/rtags#1007
The on-disk storage of cquery can also be improved. llvm+clang+libcxx+libcxxabi takes 53 minutes to index on my laptop (X1 Carbon)
Restart cquery to load the cache files:
But you can send queries when cquery is loading the cache. https://github.com/cquery-project/cquery/wiki/Design |
fwiw vscode also uses a pipe, cquery does not currently support socket-based LSP. It'd be really great if cquery was integrated into sublime text. How you choose to do so is up to you, but I'd recommend trying to leverage any existing LSP protocol support. cquery only has a couple of LSP protocol extensions, and it does so such that it should be relatively simple to extend an additional LSP client to support the additional methods. Thanks for the interest! I hope we get great sublime text integration as a result :) |
fwiw |
@papadokolos It would be really nice if you could create a client for Sublime Text. I'm so excited to highlight the two new features in the https://github.com/cquery-project/cquery/releases/tag/v20180213 release textDocument/definition in comments will search for the qualified identifier at point approximately in all symbols. |
Yes, a sublime client would be really nice. I tried it with LSP plugin, but had no luck. |
It requires around six restarts of Sublime Text to make it work with LSP, but I can assure you that it does work, partially. I managed to make it run the cquery server, and to communicate with it for diagnostics, auto-complete and goto-definition. But, unfortunately, it is unstable and sometimes behaves unexpectedly. |
Could you share your LSP configuration, please? Thanks! |
OK, I have it working and it is stable (Ubuntu 16.04). These are my user settings for LSP: {
"clients":
{
"cquery":
{
"languageId": "cpp",
"command":
[
"/opt/cquery/build/release/bin/cquery",
"--log-file=/var/log/cquery/cquery.log"
],
"scopes":
[
"source.c",
"source.c++"
],
"syntaxes":
[
"Packages/C++/C.sublime-syntax",
"Packages/C++/C++.sublime-syntax"
],
"initializationOptions":
{
"cacheDirectory": "/home/me/.cquery"
}
}
}
} Take care for cacheDirectory. Furthermore - in case you want to have a log file - make sure the folder for the log file is writable by you. |
I'm glad you worked it out! But are you sure that it is working smoothly? I, for example, have an issue with the diagnostics, which seems to always lag behind the current state of the file. For example, if a whole word causes a compilation error, only the first letter is marked. This gets fixed when I save the file. |
@papadokolos There have been a lot of changes to cquery, it is likely that it works better now :) |
I think there is some stuff we can optimize in the settings. I also saw that my code is checked while I'm writing. This is something I don't like. I should be informed about problems on save. Having a look in the log file I see much settings which can be changed through initializationOptions. I still have to invest some time into this. |
Set https://github.com/cquery-project/cquery/blob/master/src/config.h#L153 |
Here are my complete LSP settings for sublime. Maybe someone will find it helpful ...
|
Hello! 😸
I'm a C++ developer, and I'm using Sublime Text 3 as my primary editor. I recently discovered this exciting project, and I must begin with a big Thank You for this amazing effort.
If I wasn't clear yet, I would like to bring cquery to Sublime Text 😄.
For this purpose, I'll write here important information which should help you decide how to approach my request.
Introduction to Sublime Text 3
Sublime Text 3 is a text editor written in C++ at its core, and is easily hackable/extendable by using its well documented python API for plugin developers.
Currently, Sublime is pretty wide spread, and has an active (and very kind 😜 ) plugin development community. Most of the plugins are available via Package Control, the official package manager.
Sublime Text as C++ IDE
Marketing itself as a text editor, Sublime does not focus on providing IDE-like features, but rather on simplicity of use and performance. As a result, most of the C++ oriented features are coming from external plugins, similarly to vscode.
However, Sublime Text's core (which is written in C++) is very efficient, and as such, plugin developers are encouraged to use it (via the python API) in order to complete their tasks. In other words, it is better to let Sublime to do the work for you, when possible, than doing it by yourself, since it will probably be more efficient.
Furthermore, it's worth noting that everything in Sublime Text supports fuzzy searching, which is a very powerful feature, that just as well, happenes efficiently.
Currently Available features/plugins
In order to give you a complete picture, I will write both the built-in features available to a new, registered, Sublime Text user (with the newest development build), and the "most feature rich" state which combines several plugins to achieve a more C++ IDE-like experience.
Core C++ Oriented Features (Sublime Text Build 3156)
Regex based syntax highlighting
Sublime provides syntax highlighting using a custom regular expression engine, and supports both TextMate's
.tmLanguage
file format as well as as its own.sublime-syntax
file format. The core syntax highlighting files are available at Sublime's Core Packages Repository.Hashed Syntax Highlighting
As of build 3153, Sublime is able to draw different words with different colors based on their hash:
GoTo Symbol Definition/Declaration/References - file wide and project wide
Sublime indexes the entire project internally, based on the regex syntax highlighting. After it finishes, it gives you the ability to either navigate to symbol's definition/declaration/references, and to search for symbols in the current file, and even project wide. This can be done both by keyboard shorcuts and by mouse hover.
BUT, and this is a big one, this whole thing is done non sematically! All symbols with the same name are being proposed (no context filtering, even by language!), which makes it harder to find the right symbol, and many symbols are left unrecognized due to the complex C++ syntax which can't be parsed entirely by using regex alone.
Snippets
Sublime's C++ default package provides some built in snippets for
class
,if/else
,ifndef
,namesapce
, and such.Sublime Text's API Limitations
Before I go on with external plugins, I would like to mention the limitations of Sublime's API:
HTML
andCSS
formatting (minihtml). This results in one of Sublime's top weakness - the lack of a good debugger/debuggig environment.Most C++ Feature Rich Sublime Configuration - With External Plugins
Semantic Autocomplete, GotTo Declaration, Diagnostics, and Documentation on hover
Using the plugin EasyClangComplete, I have flawless semantic autocompletion of symbols (with snippets), triggered automatically when appropriate; Context aware GoTo Declaration (not definition); Real time diagnostics with inline decorations and popups; and documentation on hover, with a peek to the symbol's declaration.
This plugin is based on libclang's python bindings, and take as much information as it can from a single translation unit. That means, this plugin does not handle multiple translation units together, and does not provide project wide information.
Semantic GoTo Definition and Find All References
Using my own plugin, which is based on RTags, I implement anything that EasyClangComplete doesn't already give me. So far, I implemented GoTo Definition, Find All References, and Find Overrides of Virtual Method.
Include Paths Autocompletion
Using the plugin Include Autocomplete which is
compile_commands.json
aware.Documentation Generation
Using the plugin DoxyDoxygen, I create and update code documentation with ease. It parses classes and function's signature and generates a documentation snippet in real time. Furthermore, it is able to update the documentation when the signature changes.
Debugger - untested
Using SublimeGDB it is possible to debug your C++ program. I havn't tried it myself yet but it seems to be a popular package that tries to make the best out of the poor GUI API that is currently available.
Note
There are more plugins and features which are relevant for a C++ developer which uses Sublime Text, but these are not related to cquery's abilities in any way, so there is no point to mention them here.
How can you integrate cquery into Sublime Text
I can think of two ways in which cquery can be integrated into Sublime Text. I would love to hear your thoughts about each of them:
Information Resources
Here are useful links to the best sources for information about Sublime Text:
Does it worth the effort? Is it better than RTags?
As you can see, I got most of the stuff figured out already. But this project got me wondering whether I should stick with RTags, or switch to cquery.
cquery seems to bring everything in one package, like RTags. It looks like it is very actively developed, and you answer to issues very quickly (as opposed to RTags' developers), which is very important for me as a user. Moreover, cquery claims to be faster than RTags, and it supports LSP.
So I would like you to answer these questions:
Thank you very much for your time,
I spent the entire day to write this to you 😎
Have a lovely week!
The text was updated successfully, but these errors were encountered: