how to write package for sublimeREPL - sublimetext

The SublimeREPL plugin for ST supports lots of languages, but not all of them. It also supports writing your own configuration file for any non-default languages. Once you've written this configuration, is there any way to include it in a regular Sublime Text plugin so that when installed along with SublimeREPL it will work and support the desired language?

This turned out not to be so bad. What I wanted was to be able to distribute files in a package that would work with SublimeREPL without the user moving the files. All of the tutorials I found involved having the user place command and menu files in the SublimeREPL package directory.
Sublime Text doesn't care where it finds configuration files; they're all loaded no matter where in the packages directory they are found. Main.sublime-menu adds to the main menu and *.sublime-commands add commands.
First, fill in and rename Main.sublime-menu.template. Then do a Default.sublime-commands as well (couldn't find a template):
[
{
"caption": "SublimeREPL: XYZ Console",
"command": "run_existing_window_command", "args":
{
"id": "repl_xyz",
"file": "../XYZ-package/Main.sublime-menu"
}
}
]
The thing that was confusing me was how to refer to the menu file from the commands file, but it's simple; SublimeREPL uses the SublimeREPL as the working directory, so simply make a path from there to the menu file in your own package: ../XYZ-package/Main.sublime-menu.
Add these completed files to your package and they will work just fine with SublimeREPL.

Related

vim-go with coc.nvim: how to rename a package?

I have a file work.go opened in vim-go. It's in package oldpackagename.
I want to refactor and rename it to newpackagename. Is there some tooling for that? The reason is, the initial assumptions for oldpackagename do not apply anymore.
I know I can do search and replace stuff, but usually either
GoRename resp.
nmap <leader>rn <Plug>(coc-rename)
work just fine on automatically renaming all occurrences.
But for the package name, I get:
vim-go: [rename] SUCCESS vim-go: cannot rename the identifier at the
requested position
for GoRename and:
[coc.nvim] Error on rename: The element can't be renamed.
for coc.nvim.
Is package renaming different? Do I have to use search/replace or are my configs maybe corrupted?
Under the hood, vim-go uses either gorename or gopls to run :GoRename; the default is now gopls.
Both of these don't support renaming packages:
Open issue for gopls to support package renaming
An explicit mention of "package renaming" as a TODO feature in the gorename source code
For coc.nvim, I'm not sure, but it seems to integrate with gopls, so the same lack of support would apply.
gopls should support package renaming soon (Oct. 2022).
Its integration with vim-go should take advantage of that as soon as the feature is released.
Issue 41567 mentions CL 420958
gopls/internal/lsp: add support for package renaming
Users can now rename packages by performing a rename on the package name in package declarations.
The editor will prompt user with a dialogue text field to change the package name.
This rename feature then do the following:
Rename all the external imports of the renaming package. In case there is renaming conflicts within a file, the feature repeatedly try fresh names constructed by appending new package name with number of try times so far until succeed.
Rename all the internal references to the renaming package from its files.
Rename the directory of the renamed package and update the imports' paths of any packages nested under the renamed directory.
Rename the test package with the new package name and suffix "_test" with the current test package name ends with "_test", or just the new package name otherwise.
However:
Todo:
Add a test for the case when the renaming package's path contains "internal" as a segment.
Allow edit to the whole package path not just only the last segment of the package path
Reject renaming if the renamed subpackages don't belong to the same module with the renaming package
Check the go.mod files in the workspace to see if any replace directives need to be fixed if the renaming affects the locations of any go.mod files

Are pysa users expected to copy configuration files?

Facebook's Pysa tool looks useful, in the Pysa tutorial exercises they refer to files that are provided in the pyre-check repository using a relative path to include a path outside of the exercise directory.
https://github.com/facebook/pyre-check/blob/master/pysa_tutorial/exercise1/.pyre_configuration
{
"source_directories": ["."],
"taint_models_path": ["."],
"search_path": [
"../../stubs/"
],
"exclude": [
".*/integration_test/.*"
]
}
There are stubs provided for Django in the pyre-check repository which if I know the path where pyre check is installed I can hard-code in my .pyre_configuration and get something working but another developer may install pyre-check differently.
Is there a better way to refer to these provided stubs or should I copy them to the repository I'm working on?
Many projects have a standard development environment, allowing for hard coded paths in the .pyre_configuration file. These will usually point into the venv, or some other standard install location for dependencies.
For projects without a standard development environment, you could trying incorporating pyre init into your setup scripts. pyre init will setup a fresh .pyre_configuration file with paths that correspond to the current install of pyre. For additional configuration you want to add on top of the generated .pyre_configuration file (such as a pointer to local taint models), you can hand write a .pyre_configuration.local, which will act as an overlay and overwrite/add to the content of .pyre_configuration.
Pyre-check looks for the stubs in the directory specified by the typeshed directive in the configuration file.
The easiest way is to move stubs provided for Django in the pyre-check repository to the typeshed directory that is in the pyre-check directory.
For example, if you have installed pyre-check to the ~/.local/lib directory, move the django directory from ~/.local/lib/pyre_check/stubs to ~/.local/lib/pyre_check/typeshed/third_party/2and3/ and make sure your .pyre_configuration file will look like this:
{
"source_directories": ["~/myproject"],
"taint_models_path": "~/myproject/taint",
"typeshed": "~/.local/lib/pyre_check/typeshed"
}
In this case, your Django stubs directory will be ~/.local/lib/pyre_check/typeshed/third_parth/2and3/django
Pyre-check uses the following algorithm to traverse across the typeshed directory:
If it contains the third_party subdirectory, it uses a legacy method: enters just the two subdirectories: stdlib and third_party and there looks for any subdirectory except those with names starting with 2 but not 2and3, and looks for the modules in those subdirectories like 2and3, e.g. in third_party/2and3/
Otherwise, it enters the subdirectories stubs and stdlib, and looks for modules there, e.g. in stubs/, but not in stubs/2and3/.
That's why specifying multiple paths may be perplexing and confusing, and the easiest way is to setup the typeshed directory to ~/.local/lib/pyre_check/typeshed/ and move django to third_parth/2and3, so it will be ~/.local/lib/pyre_check/typeshed/third_parth/2and3/django.
Also don't forget to copy the .pysa files that you need to the taint_models_path directory. Don't set it up to the directory of the Pyre-check, create your own new directory and copy only those files that are relevant to you.

Not able to perform go-to-definition functionality in feature file to navigate to step definition file in a protractor-cucumber framework

Go-to-definition functionality not working on vs-code.
I have installed cucumber(gherkin) full support plugin.
Steps to replicate: Right click on steps on feature file and select go to definition.
Feature file
Gherkin code : When user access the Application
Step definition file
When('user access the Application', async function () {
await PageObject.open();
});
Expected: It should navigate to step-definitions file.
project folder structure
settings.json
install plugin: Cucumber (Gherkin) Full Support (Alexander Krechik)
create a folder: .vscode under project folder (don't in any subfolder)
create a file: settings.json under .vscode
In vscode, reopen the folder where .vscode insides to make settings take effect.
Following is the example project on my local and the go to definition worked well on it.
project folder structure
settings.json
{
"cucumberautocomplete.steps": [
"steps/*js"
],
"cucumberautocomplete.syncfeatures": "features/*feature",
"cucumberautocomplete.strictGherkinCompletion": true
}
(Remember change to your step definition and feature file path)

How can I setup vscode for Go project built with bazel?

I am trying to browse code for gVisor with VScode.
However, unlike other Go projects, gVisor is built with bazel, and the source code is not located under $GOROOT or $GOPATH. Maybe this prevents gVisor packages from being searched by VSCode go extension. Go-to-definition is not working in most cases, except for cases where the definition can be found under the same directory.
How can I setup VSCode with bazel Go projects? Especially gVisor. Thanks!
The linked gVisor rule now proxies a more canonical implementation
This setup worked for me:
In your workspace's root BUILD file you can add the following build rule
# in BUILD.bazel
load("#io_bazel_rules_go//go:def.bzl", "go_path")
go_path(
name = "gopath",
mode = "link",
deps = [
"//my/binary/here",
"//any/other/binaries/you/want/linked",
],
)
(if you don't yet have a gazelle import for the bazelbuild/go_rules, you would need to import it for bazel)
# in WORKSPACE
http_archive(
name = "io_bazel_rules_go",
sha256 = "8e968b5fcea1d2d64071872b12737bbb5514524ee5f0a4f54f5920266c261acb",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip",
],
)
Build this command to create a symlinked folder in your blaze-out at bazel-bin/gopath that contains links to each of your dependencies. You'll have to do this any time you add a new dependency. You will see a line for each symlink created.
bazel build :gopath
(assuming you're using VSCode with the Golang extension) Set your workspace settings for the go extension to point to this gopath. Note you'll need to have it be a worspace trusted extension in order for this to work.
// In .vscode/settings.json
{
"go.gopath": "/YOUR ABSOLUTE PATH TO YOUR WORKSPACE//bazel-bin/gopath"
}
Restart VSCode
Enjoy!
NOTE: if you have a go.mod file in your root dir, this will not work.
gVisor recently added a gopath BUILD rule that creates a canonical GOPATH tree from the source.
You may be able to use that the edit more effectively from VScode.

Auto compile SCSS files in Sublime Text 2

Ok, here is what I want:
I write .scss files, not .sass files
On saving the file, I get the corresponding .css file in the same folder
Now there are plenty of SASS plugins on Sublime Text2 but none seems to provide anything beyond syntax highlighting for me.
Any suggestions on how to get auto-compiling working on Sublime Text2.
I didn't find any existing plugins that did this, so here it is:
Assuming you've installed the SCSS plugin from Package Control, you can save this as Packages/User/SCSS.py.
import sublime_plugin
import subprocess
import os
from threading import Thread
def compile(input_file):
output_file = os.path.splitext(input_file)[0] + ".css"
cmd = "sass '{0}':'{1}'".format(input_file, output_file)
subprocess.call(cmd, shell=True)
class SCSS(sublime_plugin.EventListener):
def on_post_save(self, view):
scope = (view.syntax_name(view.sel()[0].b)).split().pop()
if scope == "source.scss":
input_file = view.file_name()
t = Thread(target=compile, args=(input_file,))
t.start()
Of course, this would be better as an official Package Control plugin with user configurable settings (where to save files, on/off, etc), but this meets your requirements and doesn't block the editor.
You should consider to use build system instead of dedicated plugin of it. It's very simple to do.
http://docs.sublimetext.info/en/latest/file_processing/build_systems.html
Something like this:
{
"cmd": ["sass","$file"],
"selector": "source.scss",
"path": "/usr/local/bin"
}
And just hit ctrl + b t build current file. If you have multiple builds for scss you can select one from build menu (Tools -> Build Systems).
You could use SublimeOnSaveBuild plugin.
And in plugin filter settings just leave .scss files!
It's works for just great!
I was looking for a sass/scss compiler plugin for Sublime Test, but I have my source folders separate from my css folders. So, going off the comments left on here I wrote SassBuilder that runs off a config file stored in your source folder. It has also been submitted to the Sublime Package Control repository. Once they pull the request, you can install it from there.
SassBuilder on github
Sass Builder is the new plugin which is available in Package Manager of sublime text.
This does not require any configuration. Just write your scss and hit cmd + b to compile.
Your css file will be generated in the same folder as scss.

Resources