Skip to content

Conversation

@artmoskvin
Copy link
Collaborator

This PR adds the languages parameter in the CreateProjectRequest to give users more control over which lsp servers to run in their projects. The provided languages are used instead of language detection.

This PR also introduces request validation powered by https://github.com/go-playground/validator
For example, the valid values for the languages field are Python, JavaScript, Go, and TypeScript which are the only lsp servers we support right now. I wished we could use the variables in struct tags but for now we have to enter values by hand.

I also added some filters recommended for language detection, not that I see any immediate difference, but I think those are nice to have.

err := h.Validator.Struct(request)
if err != nil {

if _, ok := err.(*validator.InvalidValidationError); ok {
Copy link
Collaborator

Choose a reason for hiding this comment

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

L28-L41 I think we can reuse this logic across handlers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could! But I don't fully understand how. Ideally, we'd make a middleware out of it but with the current contract we'll parse the payload twice (unless you know the way to pass the struct along with the request)

languages, err = pm.detectLanguages(project)
if err != nil {
log.Error().Err(err).Msg("Failed to detect project languages")
removeProjectDir(projectPath)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not related to this PR, but I think we need to nit error handling and have a defer rollback. This block is repeated too many times.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also do we really need to write to a channel?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We run project creation in a goruotine because it takes a while. That's why we used channels. But I'm open to any suggestions here. This one was my first goroutine, so it's far from ideal :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

result := <-h.Manager.CreateProject(r.Context(), request) in handler is equivalent to method invocation as far as I can tell. But let's take it outside this PR.

@artmoskvin artmoskvin force-pushed the artm/language-params branch from d15634b to 9541177 Compare October 4, 2024 11:33
@artmoskvin artmoskvin merged commit 6f9fda6 into main Oct 4, 2024
@artmoskvin artmoskvin deleted the artm/language-params branch October 4, 2024 11:58
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.

3 participants