-
-
Notifications
You must be signed in to change notification settings - Fork 85
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 "name" / "value" support for Python with
#2162
Conversation
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 is analogous to what we do for const aaa = bbb, ccc = ddd;
in typescript, where there is one scope for each subclause and one scope for the entire statement
@@ -76,6 +78,8 @@ const scopeSupportFacets = [ | |||
"value.return", | |||
"value.return.lambda", | |||
"value.field", | |||
"value.resourceManagement", |
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 concept is supported in a few languages other than Python. Here's more info, courtesy of chatgpt:
Several languages have constructs similar to Python's with
statement, designed for managing resources in a structured way. Here's a closer look at how some languages implement this with ___
-style setup:
-
C# (.NET Framework):
- Construct:
using
- Usage:
with
equivalent in C# isusing
. It's used for managing resources like file streams, network connections, or database connections. It ensures the resources are disposed of once the block is exited. - Example:
using (var resource = new Resource()) { // Use resource } // Automatic disposal of resource
- Construct:
-
Java:
- Construct: try-with-resources
- Usage: Introduced in Java 7, try-with-resources is similar to Python's
with
. It ensures that each resource is closed at the end of the statement. - Example:
try (Resource resource = new Resource()) { // Use resource } // Automatic resource closure
-
VB.NET:
- Construct:
Using
- Usage: Similar to C#, VB.NET uses
Using
for managing and disposing of resources automatically. - Example:
Using resource As New Resource() ' Use resource End Using ' Automatic disposal of resource
- Construct:
-
Swift:
- Construct:
defer
- Usage: While not a direct equivalent, Swift's
defer
statement schedules code to be executed when the current scope is exited, similar to the cleanup part of Python'swith
. - Example:
let resource = Resource() defer { resource.close() } // Use resource
- Construct:
-
F#:
- Construct:
use
- Usage: F# has a
use
keyword that is similar tousing
in C#. It's used for automatic disposal of resources. - Example:
use resource = new Resource() // Use resource
- Construct:
These constructs are primarily used for resource management to ensure that resources such as file handles, network connections, or database connections are properly released after their use, even if an error occurs. Each language has its own syntax and nuances, but the underlying principle remains the same.
Looks like C#, Java, and VB.NET are good matches, where name
and value
could be defined similarly to what we've done here for Python. The others are a bit more dicey
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.
Yeah, Java's try-with-resources was the first one to come to mind other than Python.
Don't forget the ECMAScript explicit resource management proposal
with
with
packages/common/src/scopeSupportFacets/scopeSupportFacets.types.ts
Outdated
Show resolved
Hide resolved
packages/cursorless-vscode-e2e/src/suite/fixtures/scopes/python/name.resourceManagement2.scope
Outdated
Show resolved
Hide resolved
ok @AndreasArvidsson this one has been updated based on our discussion |
Note that CI will fail until #2206 is merged |
3be886c
to
71c5288
Compare
Checklist