Skip to content

Commit 366f7a9

Browse files
authored
Resolve warning message related to document filters (DonJayamanne#1531)
Fixes DonJayamanne#1530
1 parent fd4b8f8 commit 366f7a9

10 files changed

Lines changed: 55 additions & 55 deletions

File tree

news/3 Code Health/1530.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Register language server functionality in the extension against specific resource types supporting the python language.

src/client/common/constants.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import * as path from 'path';
2-
export const PythonLanguage = { language: 'python' };
2+
3+
export const PYTHON_LANGUAGE = 'python';
4+
export const PYTHON = [
5+
{ scheme: 'file', language: PYTHON_LANGUAGE },
6+
{ scheme: 'untitled', language: PYTHON_LANGUAGE }
7+
];
38

49
export namespace Commands {
510
export const Set_Interpreter = 'python.setInterpreter';

src/client/debugger/configProviders/baseProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { injectable, unmanaged } from 'inversify';
99
import * as path from 'path';
1010
import { CancellationToken, DebugConfiguration, DebugConfigurationProvider, Uri, WorkspaceFolder } from 'vscode';
1111
import { IDocumentManager, IWorkspaceService } from '../../common/application/types';
12-
import { PythonLanguage } from '../../common/constants';
12+
import { PYTHON_LANGUAGE } from '../../common/constants';
1313
import { IConfigurationService } from '../../common/types';
1414
import { IServiceContainer } from '../../ioc/types';
1515
import { BaseAttachRequestArguments, BaseLaunchRequestArguments, DebuggerType, DebugOptions } from '../Common/Contracts';
@@ -105,7 +105,7 @@ export abstract class BaseConfigurationProvider<L extends BaseLaunchRequestArgum
105105
private getProgram(): string | undefined {
106106
const documentManager = this.serviceContainer.get<IDocumentManager>(IDocumentManager);
107107
const editor = documentManager.activeTextEditor;
108-
if (editor && editor.document.languageId === PythonLanguage.language) {
108+
if (editor && editor.document.languageId === PYTHON_LANGUAGE) {
109109
return editor.document.fileName;
110110
}
111111
}

src/client/extension.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ if ((Reflect as any).metadata === undefined) {
77
}
88
import { Container } from 'inversify';
99
import {
10-
debug, Disposable, DocumentFilter, ExtensionContext,
10+
debug, Disposable, ExtensionContext,
1111
extensions, IndentAction, languages, Memento,
1212
OutputChannel, window
1313
} from 'vscode';
1414
import { AnalysisExtensionActivator } from './activation/analysis';
1515
import { ClassicExtensionActivator } from './activation/classic';
1616
import { IExtensionActivator } from './activation/types';
1717
import { PythonSettings } from './common/configSettings';
18-
import { isPythonAnalysisEngineTest, STANDARD_OUTPUT_CHANNEL } from './common/constants';
18+
import { isPythonAnalysisEngineTest, PYTHON, PYTHON_LANGUAGE, STANDARD_OUTPUT_CHANNEL } from './common/constants';
1919
import { FeatureDeprecationManager } from './common/featureDeprecationManager';
2020
import { createDeferred } from './common/helpers';
2121
import { PythonInstaller } from './common/installer/pythonInstallation';
@@ -59,12 +59,6 @@ import { WorkspaceSymbols } from './workspaceSymbols/main';
5959
const activationDeferred = createDeferred<void>();
6060
export const activated = activationDeferred.promise;
6161

62-
const PYTHON_LANGUAGE = 'python';
63-
const PYTHON: DocumentFilter[] = [
64-
{ scheme: 'file', language: PYTHON_LANGUAGE },
65-
{ scheme: 'untitled', language: PYTHON_LANGUAGE }
66-
];
67-
6862
// tslint:disable-next-line:max-func-body-length
6963
export async function activate(context: ExtensionContext) {
7064
const cont = new Container();
@@ -110,7 +104,7 @@ export async function activate(context: ExtensionContext) {
110104

111105
// Enable indentAction
112106
// tslint:disable-next-line:no-non-null-assertion
113-
languages.setLanguageConfiguration(PYTHON_LANGUAGE!, {
107+
languages.setLanguageConfiguration(PYTHON_LANGUAGE, {
114108
onEnterRules: [
115109
{
116110
beforeText: /^\s*(?:def|class|for|if|elif|else|while|try|with|finally|except)\b.*:\s*\S+/,

src/client/terminals/codeExecution/helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { inject, injectable } from 'inversify';
55
import { Range, TextEditor, Uri } from 'vscode';
66
import { IApplicationShell, IDocumentManager } from '../../common/application/types';
7-
import { PythonLanguage } from '../../common/constants';
7+
import { PYTHON_LANGUAGE } from '../../common/constants';
88
import '../../common/extensions';
99
import { IServiceContainer } from '../../ioc/types';
1010
import { ICodeExecutionHelper } from '../types';
@@ -42,7 +42,7 @@ export class CodeExecutionHelper implements ICodeExecutionHelper {
4242
this.applicationShell.showErrorMessage('The active file needs to be saved before it can be run');
4343
return;
4444
}
45-
if (activeEditor.document.languageId !== PythonLanguage.language) {
45+
if (activeEditor.document.languageId !== PYTHON_LANGUAGE) {
4646
this.applicationShell.showErrorMessage('The active file is not a Python source file');
4747
return;
4848
}

src/client/unittests/codeLenses/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from 'vscode';
2-
import * as constants from '../../common/constants';
2+
import { PYTHON } from '../../common/constants';
33
import { PythonSymbolProvider } from '../../providers/symbolProvider';
44
import { ITestCollectionStorageService } from '../common/types';
55
import { TestFileCodeLensProvider } from './testFiles';
@@ -9,7 +9,7 @@ export function activateCodeLenses(onDidChange: vscode.EventEmitter<void>,
99

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

1414
return {
1515
dispose: () => { disposables.forEach(d => d.dispose()); }

src/test/debugger/configProvider/provider.attach.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as path from 'path';
1010
import * as TypeMoq from 'typemoq';
1111
import { DebugConfiguration, DebugConfigurationProvider, TextDocument, TextEditor, Uri, WorkspaceFolder } from 'vscode';
1212
import { IDocumentManager, IWorkspaceService } from '../../../client/common/application/types';
13-
import { PythonLanguage } from '../../../client/common/constants';
13+
import { PYTHON_LANGUAGE } from '../../../client/common/constants';
1414
import { EnumEx } from '../../../client/common/enumUtils';
1515
import { IFileSystem, IPlatformService } from '../../../client/common/platform/types';
1616
import { PythonDebugConfigurationProvider, PythonV2DebugConfigurationProvider } from '../../../client/debugger';
@@ -77,7 +77,7 @@ enum OS {
7777
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
7878
const pythonFile = 'xyz.py';
7979

80-
setupActiveEditor(pythonFile, PythonLanguage.language);
80+
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
8181

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

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

95-
setupActiveEditor(pythonFile, PythonLanguage.language);
95+
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
9696
setupWorkspaces([]);
9797

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

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

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

@@ -174,7 +174,7 @@ enum OS {
174174
}
175175
const activeFile = 'xyz.py';
176176
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
177-
setupActiveEditor(activeFile, PythonLanguage.language);
177+
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
178178
const defaultWorkspace = path.join('usr', 'desktop');
179179
setupWorkspaces([defaultWorkspace]);
180180

@@ -191,7 +191,7 @@ enum OS {
191191
}
192192
const activeFile = 'xyz.py';
193193
const workspaceFolder = createMoqWorkspaceFolder(__dirname);
194-
setupActiveEditor(activeFile, PythonLanguage.language);
194+
setupActiveEditor(activeFile, PYTHON_LANGUAGE);
195195
const defaultWorkspace = path.join('usr', 'desktop');
196196
setupWorkspaces([defaultWorkspace]);
197197

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

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

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

src/test/debugger/configProvider/provider.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as path from 'path';
1010
import * as TypeMoq from 'typemoq';
1111
import { DebugConfiguration, DebugConfigurationProvider, TextDocument, TextEditor, Uri, WorkspaceFolder } from 'vscode';
1212
import { IApplicationShell, IDocumentManager, IWorkspaceService } from '../../../client/common/application/types';
13-
import { PythonLanguage } from '../../../client/common/constants';
13+
import { PYTHON_LANGUAGE } from '../../../client/common/constants';
1414
import { IFileSystem, IPlatformService } from '../../../client/common/platform/types';
1515
import { IPythonExecutionFactory, IPythonExecutionService } from '../../../client/common/process/types';
1616
import { IConfigurationService, IPythonSettings } from '../../../client/common/types';
@@ -94,7 +94,7 @@ import { IServiceContainer } from '../../../client/ioc/types';
9494
const pythonFile = 'xyz.py';
9595
setupIoc(pythonPath);
9696

97-
setupActiveEditor(pythonFile, PythonLanguage.language);
97+
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
9898

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

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

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

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

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

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

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

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

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

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

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

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

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

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

323323
setupIoc(pythonPath, isWindows, isMac, isLinux);
324-
setupActiveEditor(pythonFile, PythonLanguage.language);
324+
setupActiveEditor(pythonFile, PYTHON_LANGUAGE);
325325

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

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

0 commit comments

Comments
 (0)