Skip to content

Commit

Permalink
Merge branch 'main' into astrochemx/codelens-commands-consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Druue authored Jul 19, 2024
2 parents 4493848 + e8ba48e commit ffcc978
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 79 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "language-tools",
"private": true,
"version": "31.0.6981",
"version": "31.0.6986",
"author": "Prisma",
"license": "Apache-2.0",
"engines": {
Expand Down
36 changes: 18 additions & 18 deletions packages/language-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions packages/language-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"name": "@prisma/language-server",
"description": "Prisma Language Server",
"displayName": "Prisma Language Server",
"version": "31.0.6981",
"version": "31.0.6986",
"author": "Prisma",
"license": "Apache-2.0",
"publisher": "Prisma",
"engines": {
"node": ">=14"
},
"prisma": {
"enginesVersion": "9721e9ba461e8bae3b4bb2acac96d8d80ef01c25",
"cliVersion": "5.17.0-dev.36"
"enginesVersion": "7484fd8557ad7be2d029bb2d4d43b6ef68a0200a",
"cliVersion": "5.18.0-dev.1"
},
"bin": {
"prisma-language-server": "dist/bin.js"
Expand All @@ -29,8 +29,8 @@
"main": "./dist/index.js",
"typings": "dist/src/index",
"dependencies": {
"@prisma/prisma-schema-wasm": "5.17.0-30.9721e9ba461e8bae3b4bb2acac96d8d80ef01c25",
"@prisma/schema-files-loader": "5.17.0-dev.36",
"@prisma/prisma-schema-wasm": "5.18.0-1.7484fd8557ad7be2d029bb2d4d43b6ef68a0200a",
"@prisma/schema-files-loader": "5.18.0-dev.1",
"@types/js-levenshtein": "1.1.3",
"js-levenshtein": "1.1.6",
"klona": "2.0.6",
Expand Down
67 changes: 66 additions & 1 deletion packages/language-server/src/__test__/rename/multi-file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ test('rename model', async () => {
`)
})

test('rename field', async () => {
test('rename field - map exists', async () => {
const helper = await getMultifileHelper('user-posts')
const user = helper.file('User.prisma')

Expand Down Expand Up @@ -168,3 +168,68 @@ test('rename field', async () => {
}
`)
})

test('rename field - map does not exist', async () => {
const helper = await getMultifileHelper('user-posts')
const user = helper.file('User.prisma')

const response = handleRenameRequest(helper.schema, user.textDocument, {
textDocument: {
uri: user.uri,
},
position: user.lineContaining('name String').characterAfter('na'),
newName: 'fullName',
})

expect(response).toMatchInlineSnapshot(`
{
"changes": {
"file:///user-posts/User.prisma": [
{
"newText": "fullName",
"range": {
"end": {
"character": 8,
"line": 3,
},
"start": {
"character": 4,
"line": 3,
},
},
},
{
"newText": " @map("name")",
"range": {
"end": {
"character": 16,
"line": 3,
},
"start": {
"character": 16,
"line": 3,
},
},
},
],
},
}
`)

expect(helper.applyChanges(response?.changes)).toMatchInlineSnapshot(`
{
"file:///user-posts/User.prisma": "/// This is the user of the platform
model User {
id String @id @default(uuid()) @map("_id")
fullName String @map("name")
email String
posts Post[]
address Address
favouriteAnimal FavouriteAnimal
}
",
}
`)
})
20 changes: 10 additions & 10 deletions packages/language-server/src/__test__/rename/single-file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ describe('Rename', () => {
{
newText: ' @map("Album")',
range: {
start: { line: 136, character: 33 },
end: { line: 136, character: 33 },
start: { line: 136, character: 34 },
end: { line: 136, character: 34 },
},
},
],
Expand Down Expand Up @@ -416,8 +416,8 @@ describe('Rename', () => {
{
newText: ' @map("authorId")',
range: {
start: { line: 4, character: 16 },
end: { line: 4, character: 16 },
start: { line: 4, character: 17 },
end: { line: 4, character: 17 },
},
},
{
Expand Down Expand Up @@ -458,8 +458,8 @@ describe('Rename', () => {
{
newText: ' @map("title")',
range: {
start: { line: 17, character: 16 },
end: { line: 17, character: 16 },
start: { line: 17, character: 17 },
end: { line: 17, character: 17 },
},
},
{
Expand Down Expand Up @@ -492,8 +492,8 @@ describe('Rename', () => {
{
newText: ' @map("humanId")',
range: {
start: { line: 25, character: 13 },
end: { line: 25, character: 13 },
start: { line: 25, character: 14 },
end: { line: 25, character: 14 },
},
},
{
Expand Down Expand Up @@ -567,8 +567,8 @@ describe('Rename', () => {
{
newText: ' @map("A_VARIANT_WITH_UNDERSCORES")',
range: {
start: { line: 8, character: 27 },
end: { line: 8, character: 27 },
start: { line: 8, character: 28 },
end: { line: 8, character: 28 },
},
},
{
Expand Down
16 changes: 9 additions & 7 deletions packages/language-server/src/lib/code-actions/rename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function printLogMessage(
}

function insertInlineRename(currentName: string, line: Line): EditsMap {
const character = lastNoNewlineCharacter(line.untrimmedText)
const character = lastNewLineCharacter(line.untrimmedText)
return {
[line.document.uri]: [
{
Expand All @@ -175,13 +175,15 @@ function insertInlineRename(currentName: string, line: Line): EditsMap {
}
}

function lastNoNewlineCharacter(lineText: string) {
for (let i = lineText.length - 1; i >= 0; i--) {
if (lineText[i] !== '\n' && lineText[i] !== '\r') {
return i
}
function lastNewLineCharacter(lineText: string) {
const i = lineText.length - 1
if (lineText[i] === '\n' && lineText[i - 1] === '\r') {
return i - 1
} else if (lineText[i] === '\n') {
return i
} else {
return 0
}
return 0
}

function insertMapBlockAttribute(oldName: string, block: Block): EditsMap {
Expand Down
54 changes: 27 additions & 27 deletions packages/vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ffcc978

Please sign in to comment.