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

Make TspClient reuseable interface #83

Merged
merged 1 commit into from
Aug 14, 2023

Conversation

sgraband
Copy link
Contributor

The TspClient is now an interface that can be used for other implementations. The existing functionality was moved to the DefaultTspClient. This means adopters now need to initialize the DefaultTspClient type instead of TspClient to get the default behavior. However this makes the package more flexible as different implementations can be provided, e.g. a proxy client in a Theia frontend.

Part of eclipse-cdt-cloud/theia-trace-extension#976

Contributed on behalf of STMicroelectronics

Note: Once this is merged i can update this PR to consume the changes.

@marco-miller marco-miller self-requested a review July 26, 2023 18:49
Copy link
Contributor

@marco-miller marco-miller left a comment

Choose a reason for hiding this comment

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

Thanks for this enabling contribution yes. So these would be my few (minor) comments.

Now this PR would require extensions [1,2,3] adaptations, so they build and work upon using it. Would you be able to contribute companion PRs for those alongside this one, accordingly? The goal would also be to further test this very PR that way, making sure that it works in [1,2,3]'s own contexts in turn. The original goal of supporting [4] remains alongside.

The concern of potentially breaking other (unforeseen) client integrations remains, though. Even if likely only a matter of renaming the type; as this has been a published API for a while now. Is there something we could do for this, say, scaffolding a backward-compatible (yet lightweight) structure first? -Which would come with a deprecation plan or so.

[1] https://github.com/eclipse-cdt-cloud/theia-trace-extension
[2] https://github.com/eclipse-cdt-cloud/vscode-trace-extension
[3] https://github.com/eclipse-cdt-cloud/vscode-trace-server
[4] eclipse-cdt-cloud/theia-trace-extension#990

tsp-typescript-client/src/protocol/http-tsp-client.ts Outdated Show resolved Hide resolved
tsp-typescript-client/src/protocol/http-tsp-client.ts Outdated Show resolved Hide resolved
@sgraband
Copy link
Contributor Author

sgraband commented Aug 7, 2023

@marco-miller I updated the PR according to your two feedback comments. I will also provide PRs in the coming days for the dependedent projects.

Regarding the breaking of other dependent projects: I think the main problem tha we have is that the new interface has the same name as the old constructor. Hence exporting a constructor for TspClient will not work if i am not mistaken. Do you have another idea on how to achieve this?

BTW, i feel like it makes sense to get this PR merge ready, before updating the PRs in the dependent projects in case we change something here.

@marco-miller
Copy link
Contributor

@marco-miller I updated the PR according to your two feedback comments. I will also provide PRs in the coming days for the dependedent projects.

Thanks again for all this.

Regarding the breaking of other dependent projects: I think the main problem tha we have is that the new interface has the same name as the old constructor. Hence exporting a constructor for TspClient will not work if i am not mistaken. Do you have another idea on how to achieve this?

We could consider keeping the legacy constructor (class) as is. While making it extend a new, differently named interface, behind the scenes -so to speak. Then add the new constructable sibling alongside that legacy one (extending that interface too). Existing clients wouldn't be broken, yet could eventually choose to switch to the new implementation.

BTW, i feel like it makes sense to get this PR merge ready, before updating the PRs in the dependent projects in case we change something here.

Agree; makes sense to me too.

@sgraband
Copy link
Contributor Author

sgraband commented Aug 8, 2023

We could consider keeping the legacy constructor (class) as is. While making it extend a new, differently named interface, behind the scenes -so to speak. Then add the new constructable sibling alongside that legacy one (extending that interface too). Existing clients wouldn't be broken, yet could eventually choose to switch to the new implementation.

Would we really provide a "separate implementation" for the old constructor? Wouldnt it be sufficient to do something like:

export class TspClient extends HttpTspClient {}

This way we do not need to provide another implementation or delegate and existings clients will not break. WDYT?

Do you have any suggestions for the name of the interface? Are we planning to rename it to TspClient once we deprecate the constructor or should the name be permanent?

@marco-miller
Copy link
Contributor

We could consider keeping the legacy constructor (class) as is. While making it extend a new, differently named interface, behind the scenes -so to speak. Then add the new constructable sibling alongside that legacy one (extending that interface too). Existing clients wouldn't be broken, yet could eventually choose to switch to the new implementation.

Would we really provide a "separate implementation" for the old constructor? Wouldnt it be sufficient to do something like:

export class TspClient extends HttpTspClient {}

This way we do not need to provide another implementation or delegate and existings clients will not break. WDYT?

Agree. I'd in fact be for the less breaking and most stable (yet still fitting) solution possible here. So, as far as HttpTspClient is as stable and predictable as TspClient was known to be.

Do you have any suggestions for the name of the interface? Are we planning to rename it to TspClient once we deprecate the constructor or should the name be permanent?

How about TraceServerProtocol? But I'd prefer that @bhufmann shares his opinion as well here. I'd foster not having to rename the interface anytime soon, even after eventually deprecating the legacy constructor.

@paul-marechal
Copy link
Member

export class TspClient extends HttpTspClient {}

No use creating a child class when all you want is an alias:

/** @deprecated use {@link HttpTspClient} directly instead. */
export const TspClient = HttpTspClient;

@paul-marechal
Copy link
Member

Do you have any suggestions for the name of the interface? Are we planning to rename it to TspClient once we deprecate the constructor or should the name be permanent?

How about TraceServerProtocol?

If I may, I'd throw TraceClient for consideration because the way the interface is defined it's all methods to interface with some Trace Server and it seems rather protocol-agnostic?

@bhufmann
Copy link
Collaborator

bhufmann commented Aug 8, 2023

Do you have any suggestions for the name of the interface? Are we planning to rename it to TspClient once we deprecate the constructor or should the name be permanent?

How about TraceServerProtocol?

If I may, I'd throw TraceClient for consideration because the way the interface is defined it's all methods to interface with some Trace Server and it seems rather protocol-agnostic?

Finding good names are often tricky. TraceServerProtocol feels a bit long and TraceClient doesn't have a clear meaning for me.

With this change TspClient is an interface. The name doesn't indicate that. In Java, I like the naming convention that interfaces start with I. But this is discouraged in the Typescript community. So, I'm ok with keeping TspClient for the interface. HttpTspClient then makes sense for the HTTP implementation.

@bhufmann
Copy link
Collaborator

bhufmann commented Aug 8, 2023

Do you have any suggestions for the name of the interface? Are we planning to rename it to TspClient once we deprecate the constructor or should the name be permanent?

How about TraceServerProtocol?

If I may, I'd throw TraceClient for consideration because the way the interface is defined it's all methods to interface with some Trace Server and it seems rather protocol-agnostic?

Finding good names are often tricky. TraceServerProtocol feels a bit long and TraceClient doesn't have a clear meaning for me.

With this change TspClient is an interface. The name doesn't indicate that. In Java, I like the naming convention that interfaces start with I. But this is discouraged in the Typescript community. So, I'm ok with keeping TspClient for the interface. HttpTspClient then makes sense for the HTTP implementation.

"TspClient" as interface name and "HttpTspClient implements TspClient" would make sense. For backwards-compatibility reasons and to avoid having to update each user of TspClient (theia-trace-extension and vscode-trace-extension) right away we don't have a choice to find a new name for the interface. Maybe using the prefix I is not such a bad idea in this case. I have seen that being done in the actual VsCode Typescript code base. So we wouldn't be the only ones :-)

WDYT?

@marco-miller
Copy link
Contributor

Adding to @bhufmann's latest proposal (which I'd foster, along with @paul-marechal's alias one): the exact list of known client extensions not to break is [1,2,3] in this previous reply. -Just a friendly reminder.

@sgraband
Copy link
Contributor Author

sgraband commented Aug 9, 2023

Thanks a lot for the suggestions! I now went with ITspClient for the interface the same naming scheme is already used for the ITspClientProvider in the theia-trace-extension.

I tried using a simple alias, which worked for the constructors, but not for the types, due to:

error TS2749: 'TspClient' refers to a value, but is being used as a type here. Did you mean 'typeof TspClient'

So instead i went for the class ... extends way, which works.

I also tested it with [2] and [3] and there seem to be no breakages. I am currently working on extending eclipse-cdt-cloud/theia-trace-extension#990 to work with these changes.

Copy link
Contributor

@marco-miller marco-miller left a comment

Choose a reason for hiding this comment

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

Thanks again for the rework. At this stage, most of the fix-up commits could be squashed, as they're review-based steps more than commitable increments. The resulting commit message(s) can be confirmed alongside.

tsp-typescript-client/src/protocol/tsp-client.ts Outdated Show resolved Hide resolved
@sgraband sgraband force-pushed the tspClientInterface branch from d16ddd1 to 3602d61 Compare August 10, 2023 07:05
The new interface is called `ITspClient`.
`ITspClient` can be used for typing and other implementations.
The existing functionality was moved to the `HttpTspClient`.
To not break the existing behavior `TspClient` is still exported as an
alias for the `HttpTspClient`, but is being deprecated.
This way adopters should be notified to migrate to `HttpTspClient`.
This makes the package more flexible as different implementations
can be provided, e.g. a proxy client in a Theia frontend.

Part of eclipse-cdt-cloud/theia-trace-extension#976

Contributed on behalf of STMicroelectronics
@sgraband sgraband force-pushed the tspClientInterface branch from 3602d61 to 95b2547 Compare August 10, 2023 12:27
Copy link
Contributor

@marco-miller marco-miller left a comment

Choose a reason for hiding this comment

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

Pending @bhufmann's 2nd review; thanks.

  • I yarn-linked this client version into the aforementioned [1,2,3] and was able to build and run tests where available.
  • I opened the files using TspClient and didn't notice new/related warnings in VSC.
  • The HttpTspClient implementation looks identical to the legacy TspClient one to me locally.

Copy link
Collaborator

@bhufmann bhufmann left a comment

Choose a reason for hiding this comment

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

It looks good to me. Works fine with theia-trace-extension and vscode-trace-extension.

Thanks for the contribution!

Copy link

@MatthewKhouzam MatthewKhouzam left a comment

Choose a reason for hiding this comment

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

Nice modularity!

@marco-miller marco-miller merged commit d8f8dcc into eclipse-cdt-cloud:master Aug 14, 2023
sgraband added a commit to eclipsesource/theia-trace-extension that referenced this pull request Aug 29, 2023
To consume the new types introduced with eclipse-cdt-cloud/tsp-typescript-client#83.
Invoke the yarn clean script before running the prepare script.
Make sure all imports are from `lib` instead of `src`.

Contributed on behalf of STMicroelectronics
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.

7 participants