Comments (3)
This is done, developers will need to install "AutomaticPackageReloader" to see code changes reflected in Sublime Text.
from lsp.
As LSP has to handle quite a lot of different stuff, splitting it into several modules is unavoidable. There are several packages out there, which could be used as an example to see how it works. You might have a look into GitSavvy or GitGutter which both do so.
There are some major facts to pay attention to, before splitting the main.py.
-
Sublime Text actively loads all modules and API classes from the root of each package (only). This is good and bad as well.
-
Modules living in the root of a package should not be included into other modules as ST will create two instances of them otherwise. One instance is created by python's import statement and one by ST's core when searching for API classes. This is known as the "double loading bug" and is of interest when working with global variables.
-
Modules living in a subdirectory are ignored by ST and therefore can be imported as often as desired without creating several instances. By placing an init.py into each sub directory python will handle them as one big file in the end. The drawback of that is ST won't automatically reload any module after modification or upgrade.
I decided to put all modules into a subdirectory anyway as there are more advantages then disadvantages.
Pros:
- The package publishes only the least required classes to ST.
- Loading time of the package is smaller then with multiple files in the root (no double loading)
- Smaller modules can be maintained easier and function may be grouped by categories
Cons:
- After modification you must manually trigger reloading the modules.
I use AutomaticPackageReloader for that. Not too inconvenient. - ST needs to be restarted after upgrading the package to apply the changes.
I added a reloader module to GitGutter, which does nearly the same as AutomaticPackageReloader and is triggered after Package Control upgrade.
About the size of each module - it depends on complexity of each module. I'd create a module for each type of function and start splitting any further if it becomes too big. pylint starts complaining if a package exceeds 500 lines of code by default. Same with number of attributes of a class (max 12 or 15), or branches in a function (12 or 15). These values may be used as a guideline to make decisions.
I would suggest a common folder with all modules in it. I called it modules in GitGutter. With a single plugin.py in the root, the console will then show
Reloading plugin LSP.plugin ...
in the console upon startup.
from lsp.
With a look onto the ongoing development and size of main.py, a module structure should be one of the next steps to keep the package maintainable.
Maybe something like:
- general language-server-protocol stuff
- client
- protocol constants
- ...
- library
- commonly used functions
- intermediate functions which handle certain server responses
- diagnostics
- references
- goto definitions
- code actions
- completions
- docstring popup rendering (handle RST, markdown, Google Docstrings, ...)
- sublime API
- commands
- events
from lsp.
Related Issues (20)
- Goto Definition throws HOT 4
- Deprecate ST3 support for LSP-* packages HOT 1
- Feature: Only format when project configured for formatting HOT 8
- Disabling/Uninstalling the package resets Sublime Text's color scheme HOT 4
- Progress for migrating to python 3.8 HOT 7
- Option to disable code lens reference counter to reduce screen clutter HOT 2
- LSP messaging does not properly handle trailing `.0` on integer values HOT 7
- Plugin does not reflect `lsp_code_actions_on_save` settings HOT 3
- Can't disable code lens in settings HOT 4
- Formatting code show in hover popups HOT 2
- LSP Slows down normal autocomplete HOT 12
- LSP.sublime-settings does not recognize lsp_code_actions_on_save configuration HOT 2
- rust-analyzer.triggerParameterHints failed. Reason: unknown request (-32601) HOT 6
- Godot v4.2 Editor language server default remote port is 6005 not 6008
- ⚠️ DOWNTIME Notice: LSP and LSP-* are migrating to Python 3.8 ⚠️
- Capabilites with selector fails to register
- ModuleNotFoundError: No module named 'wcmatch.glob' HOT 13
- Prepare for upgrade of bracex and wcmatch libraries HOT 6
- [Runtime Error] ModuleNotFoundError: No module named 'wcmatch' HOT 1
- Investigate why didSave notification is not sent if view closed immediately after saving
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lsp.