-
-
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
- Loading branch information
1 parent
706fba9
commit 301404e
Showing
6 changed files
with
92 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
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,67 @@ | ||
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 zzz', async () => { | ||
let languageServer: LanguageServer; | ||
|
||
before(async () => (languageServer = await getLanguageServer())); | ||
|
||
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