Skip to content

Add returns class command to common language features - #2271

Open
ZachWatkins wants to merge 16 commits into
talonhub:mainfrom
ZachWatkins:2266-add-returns-class-command-to-common-language-features
Open

Add returns class command to common language features#2271
ZachWatkins wants to merge 16 commits into
talonhub:mainfrom
ZachWatkins:2266-add-returns-class-command-to-common-language-features

Conversation

@ZachWatkins

Copy link
Copy Markdown
Contributor

This pull request is related to issue #2266. It implements the "returns class <user.text>" command in ./lang/tags/functions.talon.

Since ./core/snippets/snippets/classDeclaration.snippet uses PUBLIC_CAMEL_CASE as the only insertion formatter, I will assume it is fine to use for this new command.

I will submit a separate PR for the "returns global class <user.text>" command, since I am not sure whether it would be useful for languages other than PHP.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 45267ee4a8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lang/tags/functions.talon Outdated
Comment thread lang/tags/functions.talon Outdated
@chdoc

chdoc commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

I think this is fundamentally the wrong level for this change. If a language has class types, then those class types should be part of the <user.code_type> capture, so that they can be entered wherever a type is used. Further, not all languages have class types, so this global command for all programming languages does not make sense.

@AndreasArvidsson

Copy link
Copy Markdown
Collaborator

Feedback from community session. We prefer if this would be part of the user.code_type capture and would be enabled by the tag user.code_object_oriented. Basically when the tag is enabled we have a context specific implementation of the capture that allow user text. While we are doing this we should also add a setting for the class formatter. Something like: user.code_class_formatter.

@AndreasArvidsson AndreasArvidsson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

AndreasArvidsson pushed a commit that referenced this pull request Aug 15, 2026
This pull request is related to issue #2266, PR #2271, and PR #2272.

It implements the "returns global class <user.text>" command in
./lang/php/php.talon.

PHP uses
[namespaces](https://www.php.net/manual/en/language.namespaces.definition.php)
for class, interface, function, and constant definitions. Namespaces use
the `\` character to declare subnamespaces, and a global namespace
reference can be made by prefixing it with `\`. When a namespace is
declared, namespace resolution first checks whether proceeding classes
and functions are registered in that namespace. Prefixing them with "\"
explicitly declares they use the global space. Simple example:

```php
<?php
namespace App;
function currentDate(): \DateTime {
    return new \DateTime();
}
```

I believe PHP is almost unique in this behavior, which is why I am
submitting this PR to add this command to it instead of the common
language features. I couldn't find any evidence that coding languages
other than C# have a prefix which can declare that a class reference in
a type definition must resolve to the global namespace instead of the
current namespace.
@ZachWatkins

Copy link
Copy Markdown
Contributor Author

Feedback from community session. We prefer if this would be part of the user.code_type capture and would be enabled by the tag user.code_object_oriented. Basically when the tag is enabled we have a context specific implementation of the capture that allow user text. While we are doing this we should also add a setting for the class formatter. Something like: user.code_class_formatter.

I will work on the changes you requested. Thank you for merging my PRs for PHP language features.

@ZachWatkins

Copy link
Copy Markdown
Contributor Author

Feedback from community session. We prefer if this would be part of the user.code_type capture and would be enabled by the tag user.code_object_oriented. Basically when the tag is enabled we have a context specific implementation of the capture that allow user text. While we are doing this we should also add a setting for the class formatter. Something like: user.code_class_formatter.

I have implemented a change which intercepts <user.code_type> and if a code_type property is not found then the spoken text as a class formatted string will be inserted instead. I've used this in a few different code type voice commands locally and it worked as expected.

@FireChickenProductivity

Copy link
Copy Markdown
Contributor

Question for backlog session: Should we prefix the user types?

Comment thread lang/tags/object_oriented.py Outdated
Comment thread lang/tags/object_oriented.py Outdated
@ZachWatkins

ZachWatkins commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

I've made the requested changes, but as implemented my solution at this point causes the phrase "returns class date time" to insert : ClassDateTime and this is not expected behavior (expected behavior is to insert : DateTime). I will change this PR into a draft, address this, and then flag it as ready for review again.

@ZachWatkins
ZachWatkins marked this pull request as draft August 22, 2026 23:13
@ZachWatkins

ZachWatkins commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

After applying the latest changes, the following phrases resolve in a PHP file as follows:

"returns class date time" -> : DateTime
"is type class date time" -> DateTime
"type class date time" -> DateTime

When not speaking the word "class", these are the results:

"returns date time" -> : date time
"is type date time" -> date time
"type date time" -> date time

Edit: It was not acceptable to have the context capture insert arbitrary user text, so I've modified the PR.

@ZachWatkins
ZachWatkins marked this pull request as ready for review August 22, 2026 23:44

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2e7e5e0c4d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread lang/tags/object_oriented.py Outdated
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.

4 participants