Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1997e8a

Browse files
committed
Fix for formatting notebook cells. (#17650)
* Fix for formatting notebook cells. * Ensure we check language id.
1 parent 6ba6949 commit 1997e8a

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

news/2 Fixes/16980.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure we use fragment when formatting notebook cells.

src/client/common/editor.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,13 @@ export async function getTempFileWithDocumentContents(document: TextDocument, fs
248248
// because the language server is watching the file system for Python
249249
// file add/delete/change and we don't want this temp file to trigger it.
250250

251-
let fileName = `${document.uri.fsPath}.${md5(document.uri.fsPath)}.tmp`;
251+
let fileName = `${document.uri.fsPath}.${md5(document.uri.fsPath + document.uri.fragment)}.tmp`;
252252
try {
253253
// When dealing with untitled notebooks, there's no original physical file, hence create a temp file.
254254
if (isNotebookCell(document.uri) && !(await fs.fileExists(document.uri.fsPath))) {
255-
fileName = (await fs.createTemporaryFile(`${path.basename(document.uri.fsPath)}.tmp`)).filePath;
255+
fileName = (
256+
await fs.createTemporaryFile(`${path.basename(document.uri.fsPath)}-${document.uri.fragment}.tmp`)
257+
).filePath;
256258
}
257259
await fs.writeFile(fileName, document.getText());
258260
} catch (ex) {

src/client/providers/formatProvider.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import * as vscode from 'vscode';
55
import { ICommandManager, IDocumentManager, IWorkspaceService } from '../common/application/types';
6+
import { PYTHON_LANGUAGE } from '../common/constants';
67
import { IConfigurationService } from '../common/types';
78
import { IInterpreterService } from '../interpreter/contracts';
89
import { IServiceContainer } from '../ioc/types';
@@ -76,7 +77,7 @@ export class PythonFormattingEditProvider
7677
// Workaround is to resolve promise to nothing here, then execute format document and force new save.
7778
// However, we need to know if this is 'format document' or formatting on save.
7879

79-
if (this.saving) {
80+
if (this.saving || document.languageId !== PYTHON_LANGUAGE) {
8081
// We are saving after formatting (see onSaveDocument below)
8182
// so we do not want to format again.
8283
return [];

0 commit comments

Comments
 (0)