Skip to content
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

Fix indentation after string literals containing escaped characters #6440

1 change: 1 addition & 0 deletions news/2 Fixes/4241.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix indentation after string literals containing escaped characters.
44 changes: 21 additions & 23 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,7 @@ import { IDebugConfigurationService, IDebuggerBanner } from './debugger/extensio
import { registerTypes as formattersRegisterTypes } from './formatters/serviceRegistry';
import { AutoSelectionRule, IInterpreterAutoSelectionRule, IInterpreterAutoSelectionService } from './interpreter/autoSelection/types';
import { IInterpreterSelector } from './interpreter/configuration/types';
import {
ICondaService,
IInterpreterLocatorProgressService,
IInterpreterService,
InterpreterLocatorProgressHandler,
PythonInterpreter
} from './interpreter/contracts';
import { ICondaService, IInterpreterLocatorProgressService, IInterpreterService, InterpreterLocatorProgressHandler, PythonInterpreter } from './interpreter/contracts';
import { registerTypes as interpretersRegisterTypes } from './interpreter/serviceRegistry';
import { ServiceContainer } from './ioc/container';
import { ServiceManager } from './ioc/serviceManager';
Expand Down Expand Up @@ -117,7 +111,7 @@ export async function activate(context: ExtensionContext): Promise<IExtensionApi
return await activateUnsafe(context);
} catch (ex) {
handleError(ex);
throw ex; // re-raise
throw ex; // re-raise
}
}

Expand Down Expand Up @@ -154,7 +148,8 @@ async function activateUnsafe(context: ExtensionContext): Promise<IExtensionApi>

const workspaceService = serviceContainer.get<IWorkspaceService>(IWorkspaceService);
const interpreterManager = serviceContainer.get<IInterpreterService>(IInterpreterService);
interpreterManager.refresh(workspaceService.hasWorkspaceFolders ? workspaceService.workspaceFolders![0].uri : undefined)
interpreterManager
.refresh(workspaceService.hasWorkspaceFolders ? workspaceService.workspaceFolders![0].uri : undefined)
.catch(ex => console.error('Python Extension: interpreterManager.refresh', ex));

const jupyterExtension = extensions.getExtension('donjayamanne.jupyter');
Expand Down Expand Up @@ -182,7 +177,7 @@ async function activateUnsafe(context: ExtensionContext): Promise<IExtensionApi>
action: { indentAction: IndentAction.Indent }
},
{
beforeText: /^(?!\s+\\)[^#\n]+\\\s*/,
beforeText: /^(?!\s+\\)[^#\n]+\\$/,
kimadeline marked this conversation as resolved.
Show resolved Hide resolved
action: { indentAction: IndentAction.Indent }
},
{
Expand Down Expand Up @@ -334,9 +329,11 @@ function isUsingGlobalInterpreterInWorkspace(currentPythonPath: string, serviceC
function hasUserDefinedPythonPath(resource: Resource, serviceContainer: IServiceContainer) {
const workspaceService = serviceContainer.get<IWorkspaceService>(IWorkspaceService);
const settings = workspaceService.getConfiguration('python', resource)!.inspect<string>('pythonPath')!;
return ((settings.workspaceFolderValue && settings.workspaceFolderValue !== 'python') ||
return (settings.workspaceFolderValue && settings.workspaceFolderValue !== 'python') ||
(settings.workspaceValue && settings.workspaceValue !== 'python') ||
(settings.globalValue && settings.globalValue !== 'python')) ? true : false;
(settings.globalValue && settings.globalValue !== 'python')
? true
: false;
}

function getPreferredWorkspaceInterpreter(resource: Resource, serviceContainer: IServiceContainer) {
Expand Down Expand Up @@ -365,7 +362,10 @@ async function getActivationTelemetryProps(serviceContainer: IServiceContainer):
const mainWorkspaceUri = workspaceService.hasWorkspaceFolders ? workspaceService.workspaceFolders![0].uri : undefined;
const settings = configurationService.getSettings(mainWorkspaceUri);
const [condaVersion, interpreter, interpreters] = await Promise.all([
condaLocator.getCondaVersion().then(ver => ver ? ver.raw : '').catch<string>(() => ''),
condaLocator
.getCondaVersion()
.then(ver => (ver ? ver.raw : ''))
.catch<string>(() => ''),
interpreterService.getActiveInterpreter().catch<PythonInterpreter | undefined>(() => undefined),
interpreterService.getInterpreters(mainWorkspaceUri).catch<PythonInterpreter[]>(() => [])
]);
Expand All @@ -375,10 +375,10 @@ async function getActivationTelemetryProps(serviceContainer: IServiceContainer):
const usingUserDefinedInterpreter = hasUserDefinedPythonPath(mainWorkspaceUri, serviceContainer);
const preferredWorkspaceInterpreter = getPreferredWorkspaceInterpreter(mainWorkspaceUri, serviceContainer);
const usingGlobalInterpreter = isUsingGlobalInterpreterInWorkspace(settings.pythonPath, serviceContainer);
const usingAutoSelectedWorkspaceInterpreter = preferredWorkspaceInterpreter ? settings.pythonPath === getPreferredWorkspaceInterpreter(mainWorkspaceUri, serviceContainer) : false;
const hasPython3 = interpreters
.filter(item => item && item.version ? item.version.major === 3 : false)
.length > 0;
const usingAutoSelectedWorkspaceInterpreter = preferredWorkspaceInterpreter
? settings.pythonPath === getPreferredWorkspaceInterpreter(mainWorkspaceUri, serviceContainer)
: false;
const hasPython3 = interpreters.filter(item => (item && item.version ? item.version.major === 3 : false)).length > 0;

return {
condaVersion,
Expand All @@ -399,8 +399,7 @@ async function getActivationTelemetryProps(serviceContainer: IServiceContainer):
function handleError(ex: Error) {
notifyUser('Extension activation failed, run the \'Developer: Toggle Developer Tools\' command for more information.');
traceError('extension activation failed', ex);
sendErrorTelemetry(ex)
.ignoreErrors();
sendErrorTelemetry(ex).ignoreErrors();
}

interface IAppShell {
Expand All @@ -410,13 +409,12 @@ interface IAppShell {
function notifyUser(msg: string) {
try {
// tslint:disable-next-line:no-any
let appShell: IAppShell = (window as any as IAppShell);
let appShell: IAppShell = (window as any) as IAppShell;
if (activatedServiceContainer) {
// tslint:disable-next-line:no-any
appShell = activatedServiceContainer.get<IApplicationShell>(IApplicationShell) as any as IAppShell;
appShell = (activatedServiceContainer.get<IApplicationShell>(IApplicationShell) as any) as IAppShell;
}
appShell.showErrorMessage(msg)
.ignoreErrors();
appShell.showErrorMessage(msg).ignoreErrors();
} catch (ex) {
// ignore
}
Expand Down