Skip to content

Commit d397161

Browse files
feat: remove project type validation from LSP layer (aws#2103)
* feat: remove project type validation from LSP layer * refactor: remove unused validation functions from LSP layer
1 parent e4e8bbb commit d397161

File tree

4 files changed

+5
-160
lines changed

4 files changed

+5
-160
lines changed

server/aws-lsp-codewhisperer/src/language-server/netTransform/resources/SupportedProjects.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* Reference only - validation moved to backend service.
3+
*/
14
export const supportedProjects = [
25
'AspNetCoreMvc',
36
'AspNetCoreWebApi',
Lines changed: 1 addition & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai'
22
import { StartTransformRequest, TransformProjectMetadata } from '../models'
3-
import { isProject, isSolution, validateProject, validateSolution } from '../validation'
3+
import { isProject, isSolution } from '../validation'
44
import { supportedProjects, unsupportedViewComponents } from '../resources/SupportedProjects'
55
import mock = require('mock-fs')
66
import { Logging } from '@aws/language-server-runtimes/server-interface'
@@ -46,122 +46,4 @@ describe('Test validation functionality', () => {
4646
mockStartTransformationRequest.SelectedProjectPath = 'test.csproj'
4747
expect(isSolution(mockStartTransformationRequest)).to.equal(false)
4848
})
49-
50-
it('should return true when project is a supported type', () => {
51-
let mockStartTransformationRequest: StartTransformRequest = sampleStartTransformRequest
52-
const mockProjectMeta = {
53-
Name: '',
54-
ProjectTargetFramework: '',
55-
ProjectPath: 'test.csproj',
56-
SourceCodeFilePaths: [],
57-
ProjectLanguage: '',
58-
ProjectType: 'AspNetCoreMvc',
59-
ExternalReferences: [],
60-
}
61-
mockStartTransformationRequest.ProjectMetadata.push(mockProjectMeta)
62-
63-
expect(validateProject(mockStartTransformationRequest, mockedLogging)).to.equal(true)
64-
})
65-
66-
it('should return false when project is not a supported type', () => {
67-
let mockStartTransformationRequest: StartTransformRequest = sampleStartTransformRequest
68-
const mockProjectMeta = {
69-
Name: '',
70-
ProjectTargetFramework: '',
71-
ProjectPath: 'test.csproj',
72-
SourceCodeFilePaths: [],
73-
ProjectLanguage: '',
74-
ProjectType: 'not supported',
75-
ExternalReferences: [],
76-
}
77-
mockStartTransformationRequest.ProjectMetadata = []
78-
mockStartTransformationRequest.ProjectMetadata.push(mockProjectMeta)
79-
80-
expect(validateProject(mockStartTransformationRequest, mockedLogging)).to.equal(false)
81-
})
82-
83-
it('should return false when there is no project path that is the same as the selected project path', () => {
84-
let mockStartTransformationRequest: StartTransformRequest = sampleStartTransformRequest
85-
const mockProjectMeta = {
86-
Name: '',
87-
ProjectTargetFramework: '',
88-
ProjectPath: 'different.csproj',
89-
SourceCodeFilePaths: [],
90-
ProjectLanguage: '',
91-
ProjectType: 'AspNetCoreMvc',
92-
ExternalReferences: [],
93-
}
94-
mockStartTransformationRequest.ProjectMetadata = []
95-
mockStartTransformationRequest.ProjectMetadata.push(mockProjectMeta)
96-
97-
expect(validateProject(mockStartTransformationRequest, mockedLogging)).to.equal(false)
98-
})
99-
100-
// New tests for AspNetWebForms validation
101-
it('should return true when project is AspNetWebForms type', () => {
102-
let mockStartTransformationRequest: StartTransformRequest = sampleStartTransformRequest
103-
const mockProjectMeta = {
104-
Name: '',
105-
ProjectTargetFramework: '',
106-
ProjectPath: 'test.csproj',
107-
SourceCodeFilePaths: [],
108-
ProjectLanguage: '',
109-
ProjectType: 'AspNetWebForms',
110-
ExternalReferences: [],
111-
}
112-
mockStartTransformationRequest.ProjectMetadata = []
113-
mockStartTransformationRequest.ProjectMetadata.push(mockProjectMeta)
114-
115-
expect(validateProject(mockStartTransformationRequest, mockedLogging)).to.equal(true)
116-
})
117-
118-
it('should not include AspNetWebForms in unsupported projects list', () => {
119-
let mockStartTransformationRequest: StartTransformRequest = sampleStartTransformRequest
120-
121-
// Add a supported project
122-
const supportedProjectMeta = {
123-
Name: 'Supported',
124-
ProjectTargetFramework: '',
125-
ProjectPath: 'supported.csproj',
126-
SourceCodeFilePaths: [],
127-
ProjectLanguage: '',
128-
ProjectType: 'AspNetCoreMvc',
129-
ExternalReferences: [],
130-
}
131-
132-
// Add an unsupported project
133-
const unsupportedProjectMeta = {
134-
Name: 'Unsupported',
135-
ProjectTargetFramework: '',
136-
ProjectPath: 'unsupported.csproj',
137-
SourceCodeFilePaths: [],
138-
ProjectLanguage: '',
139-
ProjectType: 'UnsupportedType',
140-
ExternalReferences: [],
141-
}
142-
143-
// Add an AspNetWebForms project
144-
const webFormsProjectMeta = {
145-
Name: 'WebForms',
146-
ProjectTargetFramework: '',
147-
ProjectPath: 'webforms.csproj',
148-
SourceCodeFilePaths: [],
149-
ProjectLanguage: '',
150-
ProjectType: 'AspNetWebForms',
151-
ExternalReferences: [],
152-
}
153-
154-
mockStartTransformationRequest.ProjectMetadata = [
155-
supportedProjectMeta,
156-
unsupportedProjectMeta,
157-
webFormsProjectMeta,
158-
]
159-
160-
const unsupportedProjects = validateSolution(mockStartTransformationRequest)
161-
162-
// Should only contain the unsupported project, not the AspNetWebForms project
163-
expect(unsupportedProjects).to.have.lengthOf(1)
164-
expect(unsupportedProjects[0]).to.equal('unsupported.csproj')
165-
expect(unsupportedProjects).to.not.include('webforms.csproj')
166-
})
16749
})

server/aws-lsp-codewhisperer/src/language-server/netTransform/transformHandler.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,6 @@ export class TransformHandler {
5454
isProject,
5555
this.logging
5656
)
57-
if (isProject) {
58-
let isValid = validation.validateProject(userInputrequest, this.logging)
59-
if (!isValid) {
60-
return {
61-
Error: 'NotSupported',
62-
IsSupported: false,
63-
ContainsUnsupportedViews: containsUnsupportedViews,
64-
} as StartTransformResponse
65-
}
66-
} else {
67-
unsupportedProjects = validation.validateSolution(userInputrequest)
68-
}
6957

7058
const artifactManager = new ArtifactManager(
7159
this.workspace,

server/aws-lsp-codewhisperer/src/language-server/netTransform/validation.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import { TransformationJob } from '../../client/token/codewhispererbearertokencl
66
import { TransformationErrorCode } from './models'
77

88
/**
9-
* TEMPORARY HACK: AspNetWebForms project type is allowed in validateProject and validateSolution
10-
* functions without being added to the supportedProjects array. This is to enable WebForms to Blazor
11-
* transformation without officially supporting it yet.
9+
* Project type validation moved to backend service.
1210
*/
1311

1412
export function isProject(userInputrequest: StartTransformRequest): boolean {
@@ -19,32 +17,6 @@ export function isSolution(userInputrequest: StartTransformRequest): boolean {
1917
return userInputrequest.SelectedProjectPath.endsWith('.sln')
2018
}
2119

22-
export function validateProject(userInputrequest: StartTransformRequest, logging: Logging): boolean {
23-
var selectedProject = userInputrequest.ProjectMetadata.find(
24-
project => project.ProjectPath == userInputrequest.SelectedProjectPath
25-
)
26-
27-
if (selectedProject) {
28-
// Temporary hack: Allow AspNetWebForms project type without adding it to supportedProjects
29-
var isValid =
30-
supportedProjects.includes(selectedProject?.ProjectType) ||
31-
selectedProject?.ProjectType === 'AspNetWebForms'
32-
logging.log(
33-
`Selected project ${userInputrequest?.SelectedProjectPath} has project type ${selectedProject.ProjectType}` +
34-
(isValid ? '' : ' that is not supported')
35-
)
36-
return isValid
37-
}
38-
logging.log(`Error occured in verifying selected project with path ${userInputrequest.SelectedProjectPath}`)
39-
return false
40-
}
41-
42-
export function validateSolution(userInputrequest: StartTransformRequest): string[] {
43-
return userInputrequest.ProjectMetadata.filter(
44-
project => !supportedProjects.includes(project.ProjectType) && project.ProjectType !== 'AspNetWebForms'
45-
).map(project => project.ProjectPath)
46-
}
47-
4820
export async function checkForUnsupportedViews(
4921
userInputRequest: StartTransformRequest,
5022
isProject: boolean,

0 commit comments

Comments
 (0)