-
Notifications
You must be signed in to change notification settings - Fork 3
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
Indexing single Lingua Franca projects #181
Conversation
The question is, what if we have the following structure? ├── main_lf_root/
...
│ ├── src/ # Contains LF source files
│ │ ├── lf_project_1/
│ │ │ ├── src/ # Contains LF source files of lf_project_1
│ │ │ │ ├──SourceFile.lf
│ │ │ │ ├── lib/ # Directory for storing reusable reactors of lf_project_1
│ │ │ │ │ ├── Input.lf # Ex: reactor capturing external inputs (e.g., Microphone, Camera)
│ │ │ ├── build/ # directory containing lingo packages of lf_project_1
│ │ │ │ ├── lfc_include/ # Directory for storing reusable reactors
│ │ │ │ │ ├── lingo_downloaded_library/
│ │ ├── lf_project_2/ # Same structure as lf_project_1
... Should we consider this an LF project because it has a src/ folder? If so, we should define what qualifies as an LF project to proceed with the implementation accordingly. What do you suggest? @lhstrh @edwardalee @tanneberger |
AFAIK, what we agreed on is that the source files of a package should be in If you open VS Code in |
With the above file structure, the subdirectories with So the @vinzbarbuto 's question is valid: If you open VS Code in directory |
Out of scope? Don't we want a consistent approach to what our build tools do? |
What I meant is that this design should take what This adds a lot of complexity to this tool. Do we really need this? An alternative would be to change what |
I thought that we were implementing what's described here, and there is no mention of nested package structures in that discussion. Why do we need to support it at all? As per my earlier comment, I don't actually see a problem with the presented scenario.
If that's not what you want, then either open the IDE in a different location or reorganize your files. |
This sounds fine, but my only question would be: how do you validate the structure of the project layout? I would keep this as simple as possible. |
src/lfview/lf-data-provider.ts
Outdated
@@ -577,7 +574,7 @@ export class LFDataProvider implements vscode.TreeDataProvider<LFDataProviderNod | |||
*/ | |||
buildRoot(uri: string, type: LFDataProviderNodeType | null): LFDataProviderNode { | |||
const splittedUri = uri.split('/'); | |||
const srcIdx = splittedUri.indexOf(!type || type == LFDataProviderNodeType.LIBRARY ? 'build' : 'src'); | |||
const srcIdx = splittedUri.lastIndexOf(!type || type == LFDataProviderNodeType.LIBRARY ? 'build' : 'src'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change? This seems to relate to our discussion. The question is whether we should find the file relative to the root of the workspace, or fine the root of the package by traversing up from the file. In lfc
, we have no workspace root, so we do the latter. I think that for an IDE it makes more sense to do the former.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use the last index because the uri
passed to the buildRoot
function is an absolute file path. For example, if my workspace is opened for a project named project
with the following structure:
├── project
...
│ ├── src/ # Contains LF source files
│ │ ├── SourceFile.lf # Can also be in a subfolder, e.g. source1/SourceFile.lf
│ │ ├── lib/ # Directory for storing reusable reactors
│ │ │ ├── Input.lf # Example: reactor capturing external inputs (e.g., Microphone, Camera)
│ ├── build/ # Directory containing lingo packages
│ │ ├── lfc_include/ # Directory for storing reusable reactors
│ │ │ ├── lingo_downloaded_library/
...
Let's assume the project
in your file system has an src
folder in its absolute path. The uri
passed to the function could be something like /root/src/project/src/SourceFile.lf
. If you use indexOf
, it will find the index of the first src
folder, and the label shown in the tree view will be root
instead of project
. However, we want to locate the closest src
folder to SourceFile.lf
and use that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense depending on whether we want to let the open file dictate the behavior of the editor or whether we want the workspace to do that. Here, you're switching from the latter to the former. We have to make sure this is what we want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also leaves unanswered the question of what to do when no file is opened in the editor. Do we look down in case no file is opened and up in case there is an open file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the answer to this is here as well
This isn't what
it produces the binary in |
As you pointed out yourself, this is because In a package created by |
To be consistent with
If at least one of these conditions is satisfied, the tree view will be displayed. Otherwise, the message will be shown. |
Yes, this makes sense, but are you reasoning up from the location of the current file or down from the current workspace? I think the code suggests the former, but I want to make sure I understand you correctly. If my understanding is correct -- going back to your example -- if you open VS Code in |
"viewsWelcome": [ | ||
{ | ||
"view": "lf-lang-projects", | ||
"contents": "No Lingua Franca project found. [Learn more](https://www.lf-lang.org/docs/) about setting up a Lingua Franca project structure.\n[Open Lingua Franca Project](command:linguafranca.openFolder)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we point to a specific page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that’s the idea. Do you know which specific page?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.lf-lang.org/docs/tools/code-extension/#usage but this page it rather incomplete. Also, there is no functionality to create a new project, or a description of how to do so. Should be easy to let lingo
do it via VS Code once it's available as a library...
No. Let's consider 3 cases:
├── project
...
│ ├── src/ # Contains LF source files
│ │ ├── SourceFile.lf # Can also be in a subfolder, e.g. source1/SourceFile.lf
│ │ ├── lib/ # Directory for storing reusable reactors
│ │ │ ├── Input.lf # Example: reactor capturing external inputs (e.g., Microphone, Camera)
│ ├── build/ # Directory containing lingo packages
│ │ ├── lfc_include/ # Directory for storing reusable reactors
│ │ │ ├── lingo_downloaded_library/
... Regardless of the file opened in the editor, the tree view will display the following structure: ├── project
│ ├── Lingo Packages/
│ │ ├──lingo_downloaded_library/
│ ├── Local Libraries/
│ │ ├── Input.lf # Example: reactor capturing external inputs (e.g., Microphone, Camera)
│ ├── Source Files/
│ │ ├── SourceFile.lf
... If I open a file in the active editor that is under the same root as
├── main_lf_root/
│ ├── lf_project_1/
│ │ ├── src/ # Contains LF source files of lf_project_1
│ │ │ ├──SourceFile.lf
│ │ │ ├── lib/ # Directory for storing reusable reactors of lf_project_1
│ │ │ │ ├── Input.lf # Ex: reactor capturing external inputs (e.g., Microphone, Camera)
│ │ ├── build/ # directory containing lingo packages of lf_project_1
│ │ │ ├── lfc_include/ # Directory for storing reusable reactors
│ │ │ │ ├── lingo_downloaded_library/
│ ├── lf_project_2/ # Same structure as lf_project_1
... In this corner case, since this structure does not match the intended LF project structure, no tree view is shown. Instead, a message appears saying that no LF project has been found. To view the tree, you should open VS Code with one of the
├── main_lf_root/
│ ├── src/ # Contains LF source files
│ │ ├── lf_project_1/
│ │ │ ├── src/ # Contains LF source files of lf_project_1
│ │ │ │ ├──SourceFile.lf
│ │ │ │ ├── lib/ # Directory for storing reusable reactors of lf_project_1
│ │ │ │ │ ├── Input.lf # Ex: reactor capturing external inputs (e.g., Microphone, Camera)
│ │ │ ├── build/ # directory containing lingo packages of lf_project_1
│ │ │ │ ├── lfc_include/ # Directory for storing reusable reactors
│ │ │ │ │ ├── lingo_downloaded_library/
│ │ ├── lf_project_2/ # Same structure as lf_project_1
... This is a very strong corner case because, according to the definition I provided above, it satisfies the first condition:
Since the search regex for ├── lf_project_1
│ ├── Source Files/
│ │ ├── SourceFile.lf
├── lf_project_2
│ ├── Source Files/
│ │ ├── SourceFile.lf
... However, since this is not the behavior we want, and the directory containing multiple projects is not considered an LF project, we aim to encourage the desired behavior of opening a single project. I'm working on fixing this by excluding the following path from the regex search: To conclude, as you can see, what is displayed in the tree view is determined by the workspace you open. It does not change dynamically based on the active file opened in the editor but is defined statically when you first open a project in VSCode. The behavior we want to enforce, based on my understanding, is scenario number 1: a single LF project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are all great improvements! Let's go ahead and merge.
This PR introduces a new indexing method for the TreeView. If the data provider detects local libraries, lingo packages, or source files within a single LF project (i.e., a root directory containing a
./src
folder), the TreeView will be displayed as follows:If an LF project is not found, the following message will be displayed:
Note: For the LF project to appear in the TreeView, it must adhere to the following structure:
At least one of the following must be present in the structure for the TreeView to be displayed: source files, library files, or lingo files.