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

Resolve warning message related to document filters #1531

Merged
merged 1 commit into from
Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/3 Code Health/1530.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Register language server functionality in the extension against specific resource types supporting the python language.
7 changes: 6 additions & 1 deletion src/client/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import * as path from 'path';
export const PythonLanguage = { language: 'python' };

export const PYTHON_LANGUAGE = 'python';
export const PYTHON = [
{ scheme: 'file', language: PYTHON_LANGUAGE },
{ scheme: 'untitled', language: PYTHON_LANGUAGE }
];

export namespace Commands {
export const Set_Interpreter = 'python.setInterpreter';
Expand Down
4 changes: 2 additions & 2 deletions src/client/debugger/configProviders/baseProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { injectable, unmanaged } from 'inversify';
import * as path from 'path';
import { CancellationToken, DebugConfiguration, DebugConfigurationProvider, Uri, WorkspaceFolder } from 'vscode';
import { IDocumentManager, IWorkspaceService } from '../../common/application/types';
import { PythonLanguage } from '../../common/constants';
import { PYTHON_LANGUAGE } from '../../common/constants';
import { IConfigurationService } from '../../common/types';
import { IServiceContainer } from '../../ioc/types';
import { BaseAttachRequestArguments, BaseLaunchRequestArguments, DebuggerType, DebugOptions } from '../Common/Contracts';
Expand Down Expand Up @@ -105,7 +105,7 @@ export abstract class BaseConfigurationProvider<L extends BaseLaunchRequestArgum
private getProgram(): string | undefined {
const documentManager = this.serviceContainer.get<IDocumentManager>(IDocumentManager);
const editor = documentManager.activeTextEditor;
if (editor && editor.document.languageId === PythonLanguage.language) {
if (editor && editor.document.languageId === PYTHON_LANGUAGE) {
return editor.document.fileName;
}
}
Expand Down
12 changes: 3 additions & 9 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ if ((Reflect as any).metadata === undefined) {
}
import { Container } from 'inversify';
import {
debug, Disposable, DocumentFilter, ExtensionContext,
debug, Disposable, ExtensionContext,
extensions, IndentAction, languages, Memento,
OutputChannel, window
} from 'vscode';
import { AnalysisExtensionActivator } from './activation/analysis';
import { ClassicExtensionActivator } from './activation/classic';
import { IExtensionActivator } from './activation/types';
import { PythonSettings } from './common/configSettings';
import { isPythonAnalysisEngineTest, STANDARD_OUTPUT_CHANNEL } from './common/constants';
import { isPythonAnalysisEngineTest, PYTHON, PYTHON_LANGUAGE, STANDARD_OUTPUT_CHANNEL } from './common/constants';
import { FeatureDeprecationManager } from './common/featureDeprecationManager';
import { createDeferred } from './common/helpers';
import { PythonInstaller } from './common/installer/pythonInstallation';
Expand Down Expand Up @@ -59,12 +59,6 @@ import { WorkspaceSymbols } from './workspaceSymbols/main';
const activationDeferred = createDeferred<void>();
export const activated = activationDeferred.promise;

const PYTHON_LANGUAGE = 'python';
const PYTHON: DocumentFilter[] = [
{ scheme: 'file', language: PYTHON_LANGUAGE },
{ scheme: 'untitled', language: PYTHON_LANGUAGE }
];

// tslint:disable-next-line:max-func-body-length
export async function activate(context: ExtensionContext) {
const cont = new Container();
Expand Down Expand Up @@ -110,7 +104,7 @@ export async function activate(context: ExtensionContext) {

// Enable indentAction
// tslint:disable-next-line:no-non-null-assertion
languages.setLanguageConfiguration(PYTHON_LANGUAGE!, {
languages.setLanguageConfiguration(PYTHON_LANGUAGE, {
onEnterRules: [
{
beforeText: /^\s*(?:def|class|for|if|elif|else|while|try|with|finally|except)\b.*:\s*\S+/,
Expand Down
4 changes: 2 additions & 2 deletions src/client/terminals/codeExecution/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { inject, injectable } from 'inversify';
import { Range, TextEditor, Uri } from 'vscode';
import { IApplicationShell, IDocumentManager } from '../../common/application/types';
import { PythonLanguage } from '../../common/constants';
import { PYTHON_LANGUAGE } from '../../common/constants';
import '../../common/extensions';
import { IServiceContainer } from '../../ioc/types';
import { ICodeExecutionHelper } from '../types';
Expand Down Expand Up @@ -42,7 +42,7 @@ export class CodeExecutionHelper implements ICodeExecutionHelper {
this.applicationShell.showErrorMessage('The active file needs to be saved before it can be run');
return;
}
if (activeEditor.document.languageId !== PythonLanguage.language) {
if (activeEditor.document.languageId !== PYTHON_LANGUAGE) {
this.applicationShell.showErrorMessage('The active file is not a Python source file');
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/client/unittests/codeLenses/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from 'vscode';
import * as constants from '../../common/constants';
import { PYTHON } from '../../common/constants';
import { PythonSymbolProvider } from '../../providers/symbolProvider';
import { ITestCollectionStorageService } from '../common/types';
import { TestFileCodeLensProvider } from './testFiles';
Expand All @@ -9,7 +9,7 @@ export function activateCodeLenses(onDidChange: vscode.EventEmitter<void>,

const disposables: vscode.Disposable[] = [];
const codeLensProvider = new TestFileCodeLensProvider(onDidChange, symboldProvider, testCollectionStorage);
disposables.push(vscode.languages.registerCodeLensProvider(constants.PythonLanguage, codeLensProvider));
disposables.push(vscode.languages.registerCodeLensProvider(PYTHON, codeLensProvider));

return {
dispose: () => { disposables.forEach(d => d.dispose()); }
Expand Down
22 changes: 11 additions & 11 deletions src/test/debugger/configProvider/provider.attach.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as path from 'path';
import * as TypeMoq from 'typemoq';
import { DebugConfiguration, DebugConfigurationProvider, TextDocument, TextEditor, Uri, WorkspaceFolder } from 'vscode';
import { IDocumentManager, IWorkspaceService } from '../../../client/common/application/types';
import { PythonLanguage } from '../../../client/common/constants';
import { PYTHON_LANGUAGE } from '../../../client/common/constants';
import { EnumEx } from '../../../client/common/enumUtils';
import { IFileSystem, IPlatformService } from '../../../client/common/platform/types';
import { PythonDebugConfigurationProvider, PythonV2DebugConfigurationProvider } from '../../../client/debugger';
Expand Down Expand Up @@ -77,7 +77,7 @@ enum OS {
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
const pythonFile = 'xyz.py';

setupActiveEditor(pythonFile, PythonLanguage.language);
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);

const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { request: 'attach' } as DebugConfiguration);

Expand All @@ -92,7 +92,7 @@ enum OS {
test('Defaults should be returned when an empty object is passed without Workspace Folder, no workspaces and active file', async () => {
const pythonFile = 'xyz.py';

setupActiveEditor(pythonFile, PythonLanguage.language);
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
setupWorkspaces([]);

const debugConfig = await debugProvider.resolveDebugConfiguration!(undefined, { request: 'attach' } as DebugConfiguration);
Expand All @@ -108,7 +108,7 @@ enum OS {
}
});
test('Defaults should be returned when an empty object is passed without Workspace Folder, no workspaces and no active file', async () => {
setupActiveEditor(undefined, PythonLanguage.language);
setupActiveEditor(undefined, PYTHON_LANGUAGE);
setupWorkspaces([]);

const debugConfig = await debugProvider.resolveDebugConfiguration!(undefined, { request: 'attach' } as DebugConfiguration);
Expand Down Expand Up @@ -137,7 +137,7 @@ enum OS {
});
test('Defaults should be returned when an empty object is passed without Workspace Folder, with a workspace and an active python file', async () => {
const activeFile = 'xyz.py';
setupActiveEditor(activeFile, PythonLanguage.language);
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
const defaultWorkspace = path.join('usr', 'desktop');
setupWorkspaces([defaultWorkspace]);

Expand All @@ -156,7 +156,7 @@ enum OS {
test('Ensure \'localRoot\' is left unaltered', async () => {
const activeFile = 'xyz.py';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
setupActiveEditor(activeFile, PythonLanguage.language);
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
const defaultWorkspace = path.join('usr', 'desktop');
setupWorkspaces([defaultWorkspace]);

Expand All @@ -174,7 +174,7 @@ enum OS {
}
const activeFile = 'xyz.py';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
setupActiveEditor(activeFile, PythonLanguage.language);
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
const defaultWorkspace = path.join('usr', 'desktop');
setupWorkspaces([defaultWorkspace]);

Expand All @@ -191,7 +191,7 @@ enum OS {
}
const activeFile = 'xyz.py';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
setupActiveEditor(activeFile, PythonLanguage.language);
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
const defaultWorkspace = path.join('usr', 'desktop');
setupWorkspaces([defaultWorkspace]);

Expand All @@ -205,7 +205,7 @@ enum OS {
test('Ensure \'remoteRoot\' is left unaltered', async () => {
const activeFile = 'xyz.py';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
setupActiveEditor(activeFile, PythonLanguage.language);
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
const defaultWorkspace = path.join('usr', 'desktop');
setupWorkspaces([defaultWorkspace]);

Expand All @@ -217,7 +217,7 @@ enum OS {
test('Ensure \'port\' is left unaltered', async () => {
const activeFile = 'xyz.py';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
setupActiveEditor(activeFile, PythonLanguage.language);
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
const defaultWorkspace = path.join('usr', 'desktop');
setupWorkspaces([defaultWorkspace]);

Expand All @@ -229,7 +229,7 @@ enum OS {
test('Ensure \'debugOptions\' are left unaltered', async () => {
const activeFile = 'xyz.py';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
setupActiveEditor(activeFile, PythonLanguage.language);
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
const defaultWorkspace = path.join('usr', 'desktop');
setupWorkspaces([defaultWorkspace]);

Expand Down
26 changes: 13 additions & 13 deletions src/test/debugger/configProvider/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as path from 'path';
import * as TypeMoq from 'typemoq';
import { DebugConfiguration, DebugConfigurationProvider, TextDocument, TextEditor, Uri, WorkspaceFolder } from 'vscode';
import { IApplicationShell, IDocumentManager, IWorkspaceService } from '../../../client/common/application/types';
import { PythonLanguage } from '../../../client/common/constants';
import { PYTHON_LANGUAGE } from '../../../client/common/constants';
import { IFileSystem, IPlatformService } from '../../../client/common/platform/types';
import { IPythonExecutionFactory, IPythonExecutionService } from '../../../client/common/process/types';
import { IConfigurationService, IPythonSettings } from '../../../client/common/types';
Expand Down Expand Up @@ -94,7 +94,7 @@ import { IServiceContainer } from '../../../client/ioc/types';
const pythonFile = 'xyz.py';
setupIoc(pythonPath);

setupActiveEditor(pythonFile, PythonLanguage.language);
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);

const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, {} as DebugConfiguration);

Expand All @@ -116,7 +116,7 @@ import { IServiceContainer } from '../../../client/ioc/types';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
const pythonFile = 'xyz.py';
setupIoc(pythonPath);
setupActiveEditor(pythonFile, PythonLanguage.language);
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);

const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { noDebug: true } as any as DebugConfiguration);

Expand All @@ -137,7 +137,7 @@ import { IServiceContainer } from '../../../client/ioc/types';
const pythonPath = `PythonPath_${new Date().toString()}`;
const pythonFile = 'xyz.py';
setupIoc(pythonPath);
setupActiveEditor(pythonFile, PythonLanguage.language);
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
setupWorkspaces([]);

const debugConfig = await debugProvider.resolveDebugConfiguration!(undefined, {} as DebugConfiguration);
Expand All @@ -159,7 +159,7 @@ import { IServiceContainer } from '../../../client/ioc/types';
test('Defaults should be returned when an empty object is passed without Workspace Folder, no workspaces and no active file', async () => {
const pythonPath = `PythonPath_${new Date().toString()}`;
setupIoc(pythonPath);
setupActiveEditor(undefined, PythonLanguage.language);
setupActiveEditor(undefined, PYTHON_LANGUAGE);
setupWorkspaces([]);

const debugConfig = await debugProvider.resolveDebugConfiguration!(undefined, {} as DebugConfiguration);
Expand Down Expand Up @@ -199,7 +199,7 @@ import { IServiceContainer } from '../../../client/ioc/types';
const pythonPath = `PythonPath_${new Date().toString()}`;
const activeFile = 'xyz.py';
setupIoc(pythonPath);
setupActiveEditor(activeFile, PythonLanguage.language);
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
const defaultWorkspace = path.join('usr', 'desktop');
setupWorkspaces([defaultWorkspace]);

Expand All @@ -224,7 +224,7 @@ import { IServiceContainer } from '../../../client/ioc/types';
const activeFile = 'xyz.py';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
setupIoc(pythonPath);
setupActiveEditor(activeFile, PythonLanguage.language);
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
const defaultWorkspace = path.join('usr', 'desktop');
setupWorkspaces([defaultWorkspace]);

Expand All @@ -237,7 +237,7 @@ import { IServiceContainer } from '../../../client/ioc/types';
const activeFile = 'xyz.py';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
setupIoc(pythonPath);
setupActiveEditor(activeFile, PythonLanguage.language);
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
const defaultWorkspace = path.join('usr', 'desktop');
setupWorkspaces([defaultWorkspace]);

Expand All @@ -254,7 +254,7 @@ import { IServiceContainer } from '../../../client/ioc/types';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
const pythonFile = 'xyz.py';
setupIoc(pythonPath);
setupActiveEditor(pythonFile, PythonLanguage.language);
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);

const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, {} as DebugConfiguration);

Expand All @@ -271,7 +271,7 @@ import { IServiceContainer } from '../../../client/ioc/types';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
const pythonFile = 'xyz.py';
setupIoc(pythonPath);
setupActiveEditor(pythonFile, PythonLanguage.language);
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);

const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, {} as DebugConfiguration);

Expand All @@ -284,7 +284,7 @@ import { IServiceContainer } from '../../../client/ioc/types';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
const pythonFile = 'xyz.py';
setupIoc(pythonPath, isWindows, isMac, isLinux);
setupActiveEditor(pythonFile, PythonLanguage.language);
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);

const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, {} as DebugConfiguration);
if (isWindows) {
Expand Down Expand Up @@ -321,7 +321,7 @@ import { IServiceContainer } from '../../../client/ioc/types';
const pythonFile = 'xyz.py';

setupIoc(pythonPath, isWindows, isMac, isLinux);
setupActiveEditor(pythonFile, PythonLanguage.language);
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);

const execOutput = pyramidExists ? Promise.resolve({ stdout: pyramidFilePath }) : Promise.reject(new Error('No Module'));
pythonExecutionService.setup(e => e.exec(TypeMoq.It.isValue(args), TypeMoq.It.isAny()))
Expand Down Expand Up @@ -379,7 +379,7 @@ import { IServiceContainer } from '../../../client/ioc/types';
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
const pythonFile = 'xyz.py';
setupIoc(pythonPath);
setupActiveEditor(pythonFile, PythonLanguage.language);
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);

const debugConfig = await debugProvider.resolveDebugConfiguration!(workspaceFolder, { module: 'flask' } as any as DebugConfiguration);

Expand Down
Loading