-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow disabling handling updating files on file renames (#961)
* feat: allow disabling handling updating files on file renames * chore: changeset * test: add test for empty settings
- Loading branch information
1 parent
5a44072
commit 3a836de
Showing
7 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@astrojs/language-server": minor | ||
"astro-vscode": minor | ||
--- | ||
|
||
Allow disabling the handling of updating imports when files are renamed. This is now disabled by default in VS Code, as the Astro TypeScript plugin will handle it correctly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function sayHello() { | ||
console.log('Hello'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
import { sayHello } from "./renameThis.js"; | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import path from 'node:path'; | ||
import { expect } from 'chai'; | ||
import type { RenameFilesParams } from 'vscode-languageserver-protocol'; | ||
import { WillRenameFilesRequest } from 'vscode-languageserver-protocol'; | ||
import { type LanguageServer, getLanguageServer } from '../server.js'; | ||
|
||
const fixtureDir = path.join(__dirname, '../fixture'); | ||
|
||
describe('TypeScript - Renaming', async () => { | ||
let languageServer: LanguageServer; | ||
|
||
before(async () => (languageServer = await getLanguageServer())); | ||
|
||
it('Renames imports for files when setting is not set', async () => { | ||
const documentToBeRenamed = await languageServer.handle.openTextDocument( | ||
path.resolve(fixtureDir, 'renameThis.ts'), | ||
'typescript', | ||
); | ||
|
||
const newUri = documentToBeRenamed.uri.replace('renameThis.ts', 'renamed.ts'); | ||
|
||
const edits = await languageServer.handle.connection.sendRequest(WillRenameFilesRequest.type, { | ||
files: [ | ||
{ | ||
oldUri: documentToBeRenamed.uri, | ||
newUri: newUri, | ||
}, | ||
], | ||
}); | ||
|
||
expect(edits).to.not.be.null; | ||
}); | ||
|
||
it('Does not rename imports for files when setting is disabled', async () => { | ||
await languageServer.handle.updateConfiguration({ | ||
astro: { | ||
updateImportsOnFileMove: { | ||
enabled: false, | ||
}, | ||
}, | ||
}); | ||
|
||
const documentToBeRenamed = await languageServer.handle.openTextDocument( | ||
path.resolve(fixtureDir, 'renameThis.ts'), | ||
'typescript', | ||
); | ||
const newUri = documentToBeRenamed.uri.replace('renameThis.ts', 'renamed.ts'); | ||
|
||
const edits = await languageServer.handle.connection.sendRequest(WillRenameFilesRequest.type, { | ||
files: [ | ||
{ | ||
oldUri: documentToBeRenamed.uri, | ||
newUri: newUri, | ||
}, | ||
], | ||
} satisfies RenameFilesParams); | ||
|
||
expect(edits).to.be.null; | ||
}); | ||
|
||
it('Renames imports for files when setting is enabled', async () => { | ||
await languageServer.handle.updateConfiguration({ | ||
astro: { | ||
updateImportsOnFileMove: { | ||
enabled: true, | ||
}, | ||
}, | ||
}); | ||
|
||
const documentToBeRenamed = await languageServer.handle.openTextDocument( | ||
path.resolve(fixtureDir, 'renameThis.ts'), | ||
'typescript', | ||
); | ||
const newUri = documentToBeRenamed.uri.replace('renameThis.ts', 'renamed.ts'); | ||
|
||
const edits = await languageServer.handle.connection.sendRequest(WillRenameFilesRequest.type, { | ||
files: [ | ||
{ | ||
oldUri: documentToBeRenamed.uri, | ||
newUri: newUri, | ||
}, | ||
], | ||
}); | ||
|
||
expect(edits).to.not.be.null; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters