Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workspace management #92

Closed
wants to merge 48 commits into from
Closed

Add workspace management #92

wants to merge 48 commits into from

Conversation

Val95240
Copy link

@Val95240 Val95240 commented Mar 9, 2020

Hey !
I needed to have workspace management for my projects, and I already used your plugin so I modified it to fulfill my needs. I changed a bit of code, but the basis is still the same.
I didn't document my modifications yet, but normally the name of the methods are pretty self-descriptive.
I don't know if you're interested in this feature, theoretically everything works fine and the tests have been successful until now, but I didn't test it on different OS (even if no features should be OS-dependant) so you may want to check on your side if you're interested in merging.

The features I added are : creation, opening, opening in a new window, renaming and removing of workspaces. By default, if only one workspace exists, everything works as before and the upgrade should be transparent for the user.
If you want more details about the modifications, feel free to ask !

@randy3k
Copy link
Owner

randy3k commented May 20, 2020

@Val95240 Sorry for the late reply. I read it on mobile and have totally forgotten to reply later when I went back to my desktop.

While I really love the idea of workspace management here. But it is a huge change in the code base and it makes merging the PR difficult. It would be nice if you could keep the number of changes minimal.

@TerminalFi
Copy link

Hey !
I needed to have workspace management for my projects, and I already used your plugin so I modified it to fulfill my needs. I changed a bit of code, but the basis is still the same.
I didn't document my modifications yet, but normally the name of the methods are pretty self-descriptive.
I don't know if you're interested in this feature, theoretically everything works fine and the tests have been successful until now, but I didn't test it on different OS (even if no features should be OS-dependant) so you may want to check on your side if you're interested in merging.

The features I added are : creation, opening, opening in a new window, renaming and removing of workspaces. By default, if only one workspace exists, everything works as before and the upgrade should be transparent for the user.
If you want more details about the modifications, feel free to ask !

What OS have you tested. This looks like a nice feature

@Val95240
Copy link
Author

Sorry I didn't have much time these last months to work on that.

@randy3k I understand your concern, it's true that I had to change quite a bit of the code base, but as I said, I tried to copy your code base as much as possible to mitigate this. So for example the new methods add_workspace, remove_workspace or rename_workspace are pretty much the same as their equivalent for projects.
I also pushed some documentation for the functions I added in the hope of making the modifications clearer and more manageable.
Unfortunately, dealing with sublime workspaces was not trivial and I don't think I could greatly reduce the number of modifications to the original code without losing some basic features or some safety checks. I'd understand if you didn't have time to review the code, but that's pretty much the best I can do...

@TheSecEng I tested the feature on Linux (Ubuntu 18.04 and 20.04) and Windows 10, but not on Mac OS as I don't have an easy access to this OS. However, the modifications I added should be OS independent as I only built on the existing base code which seems to work everywhere. Feel free to test the feature on other OS if you have the opportunity !

@tukusejssirs
Copy link

@Val95240, I tried to clone your repo in order to test it out. I could not get is work with my projects saved in Packages/User/Projects/ folder (default in the upstream version). I don’t code in Python, but I noticed you mention some project folders in some PyDocs. Did you change some paths or whatever?

Just to be clear: I cannot open Open Project nor Open Project in New Window. Note that I did not test you package intensively.

BTW, I am on Fedora 32, ST3 3211, should that matter.

@Val95240
Copy link
Author

Val95240 commented Oct 7, 2020

@tukusejssirs It's difficult to say what could have gone wrong in your case, but my main theory is that the file that contains your recently opened projects Packages/User/Projects/recent.json isn't compatible with the update. To fix that, you can either call the ProjectManager Clear Recent Projects function, delete the file yourself or pull the commit I just pushed that will make the code do it for you automatically.
Please tell me if it worked !

By the way, you don't have to clone the repository to install the package, you can call Package Control: Add Repository in Sublime and add the URL to the git repo (https://github.com/Val95240/ProjectManager), and then this is the version that will be installed when calling Package Control: Install Package -> ProjectManager. Hope this will make it easier for you !

@tukusejssirs
Copy link

@Val95240, thanks for your answer!

It still does not work.

As for adding repo to Package Manager, I tried that before posting my first comment and even now. It works only when I remove the original/upstream (randy3k’s) version. On the other hand, I prefer installing such repos manually (I prefer updating them manually too). → Therefore, IMHO it is not easier, at least not for me.

When I find a bit more time, I’ll try your fork on a clean ST3.

@Val95240
Copy link
Author

Hey !
I'm sorry that it didn't fix your issue. Unfortunately I don't have any specific idea about what goes wrong on your side, and I tried to test more extensively the plugin on my computer but I couldn't reproduce the issue.
When you try to call the plugin, do you have an error message in the console (ctrl+`​ to open it) ? If so, could you send it to me ? Either here or on a new issue on my github repo, that could give me an idea on the origin of the bug and I could look deeper into it.
Thanks !

@tukusejssirs
Copy link

tukusejssirs commented Oct 12, 2020

@Val95240, the console log contains the following error when I click on Projects → Project Manager → Project Manager:

Traceback (most recent call last):
  File "/opt/sublime_text/sublime_plugin.py", line 1052, in run_
    return self.run()
  File "/home/ts/.config/sublime-text-3/Packages/prman_val95240/project_manager.py", line 1030, in run
    self.manager = Manager(self.window)
  File "/home/ts/.config/sublime-text-3/Packages/prman_val95240/project_manager.py", line 141, in __init__
    if self.reorganize_files(self.projects_path):
  File "/home/ts/.config/sublime-text-3/Packages/prman_val95240/project_manager.py", line 196, in reorganize_files
    os.mkdir(directory)
FileExistsError: [Errno 17] File exists: '/home/ts/.config/sublime-text-3/Packages/User/Projects/ts'

After seeing that, I removed ~/.config/sublim-text-3 (after backing it up) and tried out your repo and it works as expected.

Note that there is no error when using the upstearm version.


I think that folder creation should not fail when it already exists. A mere warning would be enough if at all needed.

@tukusejssirs
Copy link

@Val95240, now it works as expected.

However, I kind of miss a way to change the worspaces within a project, that is:

  • in Projects → Project Manager, there should be Open a Workspace that would list all available workspaces for the particular project;
  • in the sidebar, we could have a list (a collapsable tree) with workspaces connected with the particular project.

@Val95240
Copy link
Author

Thanks for your feedback ! You're right, I didn't plan the case where the user already have a directory with the same name as a project in the User/Projects folder, it should be good now.

To change workspace within a project, there's actually an Open Workspace command:

  • in Project -> Project Manager
  • in the command palette (Ctrl+Shift+P)
  • you can add a shortcut to it (cf. Preferences -> Package Settings -> ProjectManager -> Keybindings and this question in the README to enable it)

However, for these commands to do something, you must have several workspaces in your project already: you can create a new one by opening a project, and calling Project -> Project Manager -> Add New Workspace, or Add New Workspace in the command palette. Once you have several workspaces, the Open Workspace command will actually list them for you to choose which one you want to open.
Tell me if that's not what you were looking for !

@tukusejssirs
Copy link

  1. Open Workspace indeed is in the main menu (Projects → Project Manager) and in the command palette, however, it is missing from the Projects →Project Manager → Project Manager (I have no idea how to call it; its command is project_manager). In the upstream PM, all commands (items) from Projects → Project Manager menu are listed in project_manager overlay (or what it is). I miss it there.

  2. I have already create sevel keybinding for PM. 😃

  3. I have created several workspaces using your Add New Workspace while a particular project was open. When I Open Workspace using your PM version, it does not work (no overlay to choose workspaces is output). I need to close the project (windows) and re-open it. Then it works as expected.

  4. Another quite interesting bug occured to me, but I am not sure what or why happens (I have no idea how to debug this nor get some error log). When using your downstream PM version (i.e. this does not happen using the upstream version), I created a new project (it does not matter if I create it using the ST3 built-in Projects → Save Project As or the PM command) and then re-open it (either while it is open or closes), it crashes, closes the currently open window (in foreground; other windows stay open) or the window that would be open (if I try to open the project in a new window). Nothing really happens. OR Sometimes it opens a different project/workspace. This is quite annoying bug.

  5. Slightly OT: I use subfolders under Packages/User/Projects in order to group projects. When a project called work is in a subfolder work (note that the project name and the subfolder name is same; this is kind of the default project for a particular group for me) and I delete that project, the whole folder is deleted. This might the issue in the upstream PM too.

  6. Slightly OT: It might be a nice idea to output the subfolder name in the list of projects/workspaces (e.g. work/project_1 or work/worspace_1; see also Output project name in statusbar #96, which deals with the same, but outputs it in the status bar).


Note that I always have my projects in the Projects/ folder. I don’t want to recreate the projects as there are several hundreds of files open across all my projects.

@Val95240
Copy link
Author

Actually, the option to open a different workspace exists in the location you are describing (Projects → Project Manager → Project Manager), but the particularity is that it is available only if it could be applied, i.e. if the project has more than one workspace.
And from the different weird behaviours and bugs you are describing, I think the plugin might not be working in your case because of the organization of your Projects/ folder.

Originally, with randy3k's default plugin, the .sublime-project and .sublime-workspace files were all saved in the folder without a specific subfolder for each project. Now, to deal with workspaces, I regrouped these files in a common folder for each project, but I think that your own organization is messing with the assumed one.

From what you're describing, I think that the command Add New Workspace doesn't work or at least doesn't save the new workspace in the right place, so that the plugin doesn't see it later and it could be why you're not seeing the option to Open Workspace appear in the location you described. In fact, I think that it might be the cause of your items 1., 3. and 4.

Now, I hear your need of self organizing your Projects folder, and it could be interesting to allow projects gathering in larger groups. In order for me to test what's messing things up and try to fix it, could you describe the file tree of your Projects folder ? For example, for the plugin, I assumed it would be

User/Projects/
|  Foo/
|  |- Foo.sublime-project
|  |- Foo.sublime-workspace             # Default workspace of this project
|  \- OtherWorkspace.sublime-workspace
|
|  Bar/
|  |- Bar.sublime-project
|  |- Bar.sublime-workspace
|  ...

but you seem to have a different one (if I understood well).

@tukusejssirs
Copy link

The structure is similar to to the one you presented, however, with two differences:

  1. Each subfolders (e.g. Foo or Bar) can contain one or more projects and workspaces (each workspace is associated to exactly one project).
  2. Each workspace is located in the same folder as the project the workspace is associated with.
  3. Currently, I have some projects/workspaces in the main folder (User/Projects). Those are from a period before I started to group projects/workspaces into subfolders. I want to move them into a subfolder, but did not found some time to accomplish this yet.

Note that I usually name a main project the same as the subfolder (e.g. Foo/Foo.sublime-project), however, I don’t this it should be made a hard-coded rule.

@Val95240
Copy link
Author

I tried to test thoroughly the plugin with the same organisation of the User/Projects folder as you, but unfortunately I couldn't reproduce any bug. Sorry, I'm really not sure what's messing things up in your case, and it is pretty much impossible to debug in these conditions...

I checked and in my case, the plugin works:

  • with several projects and workspaces in the same folder
  • with subfolders in the main project folder
  • when the project folders have a different name from the project file
    so in my case, this structure works flawlessly:
User/Projects/
|  Foo/
|  |- Group1/
|  |  |- Foo.sublime-project
|  |  |- Foo.sublime-workspace             # Default workspace of this project
|  |  \- OtherWorkspace.sublime-workspace
|  |
|  |- Group2/
|  |  |- Proj1.sublime-project
|  |  |- Proj1.sublime-workspace
|  |  |- Proj2.sublime-project
|  |  |- Proj2.sublime-workspace
|  |  \- Proj2Other.sublime-workspace
|
|  Bar/
|  |- OtherName.sublime-project
|  |- OtherName.sublime-workspace
|  ...

Moreover, if you have projects or workspaces directly in the main folder (User/Projects), the plugin should automatically reorganize them into a subdirectory of their own (with the same name as the .sublime-project file). If, when you execute any command of the plugin, it doesn't happen, that means that there's an issue quite early in the execution, maybe sublime doesn't have write permission in your Projects folder ?

I'm not really sure what you can do to fix all your issues, my main advice would be to delete your entire User/Projects folder (with a backup obviously) and copy back your saved project directories one by one to see which one may cause the issues. Hopefully you can then recreate the broken ones from the plugin to guaranty they work this time.

Regarding your remark about printing the subfolder name in the list of projects, I just pushed a commit in that sense: now, in the example tree from above, the projects Foo and Proj1 will appear as Foo/Foo and Foo/Proj1 in the list. I didn't want them to appear as Foo/Group1/Foo because then every default project will be named Proj/Proj and I find it unnecessary.

@tukusejssirs
Copy link

@Val95240, I’ve just tried you latest version. Below is described what exactly I did.

The steps I took
  1. I removed the upstream Project Manager from ST3.

  2. I removed all files and folders from the Projects/ folder, while leaving the Projects/ folder empty.

  3. I added the downstream repo URL to Package Control.

  4. I installed downstream PM.

  5. I opened bunch of files and saved them as a test project in a test/ subfolder. Note that I always create projects using Project → Save Project As (using a keyboard shortcut).

  6. While the project was open, I create a new workspace named test2. In it, I closed all open files and open one, different file.

  7. Now I wanted to switch to the other, Default workspace, however, it just re-opened (flashed the ST3 window) the current (test2) workspace. When I wanted to open the test2 workspace, it simply crashed ST3 (closed the window).

  8. When I examined the Projects/test/ folder, the workspaces are there (as files), however, the open files are not open anymore (in the workspace JSONs). The test (default) workspace contains the file I have open in test2 workspace and the test2 workspace is empty.


Regarding your remark about printing the subfolder name in the list of projects, I just pushed a commit in that sense: now, in the example tree from above, the projects Foo and Proj1 will appear as Foo/Foo and Foo/Proj1 in the list. I didn't want them to appear as Foo/Group1/Foo because then every default project will be named Proj/Proj and I find it unnecessary.

I did not notice any project name in the statusbar yet. Do I have to enable them somehow?

Note that I also create a project asdf under test/ subfolder, but it still showed as asdf in the PM overlay list.

A suggestion: when/if you implement the project name output in the statusbar, I think it might be better to output the name of the workspace too, unless it is the default workspace; for example:

Statusbar Project Workspace
[foo] foo.sublime-project foo.sublime-workspace
[foo:baz] foo/bar.sublime-project baz.sublime-workspace
[foo/foo] foo/foo.sublime-project foo/foo.sublime-workspace
[foo/bar] foo/bar.sublime-project foo/bar.sublime-workspace
[foo/bar:baz] foo/bar.sublime-project foo/baz.sublime-workspace

@Val95240
Copy link
Author

Okay I'm not sure but I think I found and fixed the issue. It was a small problem with the automatic closing of empty workspaces, and my guess is that it's the reason you sometimes saw windows appearing and disappearing instantly.
If I'm not mistaken, what happened in your case is:

  1. When you created a new workspace, it must have closed immediately, leaving you in your Default workspace. You then closed every file from the Default workspace (a new workspace is always created empty, so the files you closed couldn't be in the new ws)

  2. You wanted to switch to Default but you were still in it, so it "flashed". Then when trying to open the new test workspace which was still completely empty, it once again instantly closed

And in 8., your description of the .sublime-workspace files corresponds to that situation so that should be it.
I just pushed a fix, so please try it and tell me if you're still having any issues !

Note that I also create a project asdf under test/ subfolder, but it still showed as asdf in the PM overlay list.

That's what I tried to explain in my previous message, a file Projects/test/asdf.sublime-project will be displayed as only asdf, and a file in a subfolder as Projects/test/subtest/asdf.sublime-project will be displayed as test/asdf (and not subtest/asdf). I made this choice because I don't want single projects to appear as Proj/Proj every time.

I did not notice any project name in the statusbar yet. Do I have to enable them somehow?

Regarding the status bar display, I didn't implement it yet, I only worked on the display of the names in the PM overlay list. However it could be interesting so I might work on that when I have the time, and I definitely will take your suggestions into account, thanks !

@tukusejssirs
Copy link

I confirm that the issue described in this comment of mine (removing files from workspaces and subsequently crashing ST3) is fixed in the latest commit of the downstream repo.

I had to do the following:

  • remove the upstream repo;
  • add the downstream repo;
  • back up Projects/ folder;
  • remove the Projects/ folder;
  • (probably) open the Project Manager project list overlay (I believe this creates the JSON files in the Projects/ folder);
  • copy back the projects and workspaces from the backup to Projects/ folder (but only them, not the JSON files).

Notes:

  • When creating new workspace, it opens a blank window (one without any files open), which IMO is the correct behaviour. 😃 👍
  • Without removing Projects/ folder, I tested tthe issue twice. First time it still occured, the other time it did not.
  • In the downstream repo, the loading time of the projects list overlay tooks about 0.8 seconds, however in the upstream repo, it takes about 0.1 seconds. Can’t this be improved?

That's what I tried to explain in my previous message, a file Projects/test/asdf.sublime-project will be displayed as only asdf, and a file in a subfolder as Projects/test/subtest/asdf.sublime-project will be displayed as test/asdf (and not subtest/asdf). I made this choice because I don't want single projects to appear as Proj/Proj every time.

Well, this somewhat bugs me. I see you want to remove the of the subfolder (test), however, I’d like to keep it.

Reasoning: I use the Projects/* subfolders as (real-life) project groups to group subprojects. The subprojects (Sublime projects) can have same names (like proj1/test and proj2/test). Also note that I name the subprojects (Sublime projects) without the proj1 in their names (because I deam them as duplicity) and even if the subprojects have different names, it might be easier to know what project (subfolder) it is part of.

If you still require your current implementation, I suggest to add an option for this in the package settings.

@Val95240 Val95240 force-pushed the master branch 4 times, most recently from dbfaec3 to d36df7d Compare November 12, 2022 20:32
@Val95240 Val95240 deleted the branch randy3k:master November 14, 2022 18:04
@Val95240 Val95240 closed this Nov 14, 2022
@Val95240 Val95240 deleted the master branch November 14, 2022 18:04
@Val95240 Val95240 restored the master branch November 14, 2022 18:26
@Val95240 Val95240 deleted the master branch November 14, 2022 18:29
@Val95240 Val95240 restored the master branch November 14, 2022 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants