Skip to content

Cherry picks from main for point release #17665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 13, 2021
1 change: 1 addition & 0 deletions news/2 Fixes/16980.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure we use fragment when formatting notebook cells.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"id": "pythonWelcome",
"title": "Get started with Python development",
"description": "Your first steps to set up a Python project with all the powerful tools and features that the Python extension has to offer!",
"when": "workspacePlatform != webworker",
"steps": [
{
"id": "python.installPythonWin",
Expand Down
6 changes: 4 additions & 2 deletions src/client/common/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,13 @@ export async function getTempFileWithDocumentContents(document: TextDocument, fs
// because the language server is watching the file system for Python
// file add/delete/change and we don't want this temp file to trigger it.

let fileName = `${document.uri.fsPath}.${md5(document.uri.fsPath)}.tmp`;
let fileName = `${document.uri.fsPath}.${md5(document.uri.fsPath + document.uri.fragment)}.tmp`;
try {
// When dealing with untitled notebooks, there's no original physical file, hence create a temp file.
if (isNotebookCell(document.uri) && !(await fs.fileExists(document.uri.fsPath))) {
fileName = (await fs.createTemporaryFile(`${path.basename(document.uri.fsPath)}.tmp`)).filePath;
fileName = (
await fs.createTemporaryFile(`${path.basename(document.uri.fsPath)}-${document.uri.fragment}.tmp`)
).filePath;
}
await fs.writeFile(fileName, document.getText());
} catch (ex) {
Expand Down
3 changes: 2 additions & 1 deletion src/client/providers/formatProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

if (this.saving) {
if (this.saving || document.languageId !== PYTHON_LANGUAGE) {
// We are saving after formatting (see onSaveDocument below)
// so we do not want to format again.
return [];
Expand Down