Example #1
0
    test('class methods', async () => {
        if (!await isPython3) {
            return;
        }
        let textDocument = await vscode.workspace.openTextDocument(filePep526);
        await vscode.window.showTextDocument(textDocument);
        assert(vscode.window.activeTextEditor, 'No active editor');
        let position = new vscode.Position(20, 4);
        let list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
        assert.notEqual(list.items.filter(item => item.label === 'a').length, 0, 'method a not found');

        position = new vscode.Position(21, 4);
        list = await vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
        assert.notEqual(list.items.filter(item => item.label === 'b').length, 0, 'method b not found');
    });
 test('Get Code Block (for in)', done => {
     let textDocument: vscode.TextDocument;
     return vscode.workspace.openTextDocument(FILE_WITH_CELLS).then(document => {
         textDocument = document;
         return vscode.window.showTextDocument(textDocument);
     }).then(editor => {
         assert(vscode.window.activeTextEditor, 'No active editor');
         editor.selection = new vscode.Selection(16, 0, 16, 0);
         return codeHelper.getSelectedCode().then(code => {
             const end = textDocument.lineAt(18).range.end;
             const start = editor.selection.start;
             assert.equal(code, textDocument.getText(new vscode.Range(start, end)), 'Text is not the same');
         });
     }).then(done, done);
 });
Example #3
0
function showSource(mdUri: vscode.Uri) {
	if (!mdUri) {
		return vscode.commands.executeCommand('workbench.action.navigateBack');
	}

	const docUri = vscode.Uri.parse(mdUri.query);
	for (const editor of vscode.window.visibleTextEditors) {
		if (editor.document.uri.toString() === docUri.toString()) {
			return vscode.window.showTextDocument(editor.document, editor.viewColumn);
		}
	}

	return vscode.workspace.openTextDocument(docUri)
		.then(vscode.window.showTextDocument);
}
Example #4
0
        test('should correctly format ' + path.basename(inFile), () => {
            let expectedText = fs.readFileSync(outFile);
            let textDocument: vscode.TextDocument;

            return vscode.workspace.openTextDocument(inFile).then(document => {
                textDocument = document;
                return formatService.provideDocumentFormattingEdits(document);
            }).then(edits => {
                let workspaceEdit = new vscode.WorkspaceEdit();
                workspaceEdit.set(textDocument.uri, edits);
                return vscode.workspace.applyEdit(workspaceEdit);
            }).then(() => {
                assert.equal(textDocument.getText(), expectedText);
            });
        });
  // Open the created component in the editor
  public openFileInEditor(folderName): Q.Promise<TextEditor> {
    const deferred: Q.Deferred<TextEditor> = Q.defer<TextEditor>();
    var inputName: string = path.parse(folderName).name;;
    var fullFilePath: string = path.join(folderName, `${inputName}.component.ts`);

    workspace.openTextDocument(fullFilePath).then((textDocument) => {
      if (!textDocument) { return; }
      window.showTextDocument(textDocument).then((editor) => {
        if (!editor) { return; }
        deferred.resolve(editor);
      });
    });

    return deferred.promise;
  }
Example #6
0
	test('editor, assign and check view columns', () => {

		return workspace.openTextDocument(join(workspace.rootPath, './far.js')).then(doc => {
			let p1 = window.showTextDocument(doc, ViewColumn.One).then(editor => {
				assert.equal(editor.viewColumn, ViewColumn.One);
			});
			let p2 = window.showTextDocument(doc, ViewColumn.Two).then(editor => {
				assert.equal(editor.viewColumn, ViewColumn.Two);
			});
			let p3 = window.showTextDocument(doc, ViewColumn.Three).then(editor => {
				assert.equal(editor.viewColumn, ViewColumn.Three);
			});
			return Promise.all([p1, p2, p3]);
		});
	});
Example #7
0
				execute: () => {
					this._client.logTelemetry('js.hintProjectExcludes.accepted');
					onExecute();
					this._item.hide();

					let configFileUri: vscode.Uri;
					if (vscode.workspace.rootPath && dirname(configFileName).indexOf(vscode.workspace.rootPath) === 0) {
						configFileUri = vscode.Uri.file(configFileName);
					} else {
						configFileUri = vscode.Uri.parse('untitled://' + join(vscode.workspace.rootPath || '', 'jsconfig.json'));
					}

					return vscode.workspace.openTextDocument(configFileName)
						.then(vscode.window.showTextDocument);
				}
Example #8
0
	context.subscriptions.push(vscode.commands.registerCommand('_markdown.didClick', (uri: string, line) => {
		const sourceUri = vscode.Uri.parse(decodeURIComponent(uri));
		return vscode.workspace.openTextDocument(sourceUri)
			.then(document => vscode.window.showTextDocument(document))
			.then(editor =>
				vscode.commands.executeCommand('revealLine', { lineNumber: Math.floor(line), at: 'center' })
					.then(() => editor))
			.then(editor => {
				if (editor) {
					editor.selection = new vscode.Selection(
						new vscode.Position(Math.floor(line), 0),
						new vscode.Position(Math.floor(line), 0));
				}
			});
	}));
Example #9
0
	return createRandomFile(initialContents).then(file => {
		return vscode.workspace.openTextDocument(file).then(doc => {
			return vscode.window.showTextDocument(doc).then((editor) => {
				return run(editor, doc).then(_ => {
					if (doc.isDirty) {
						return doc.save().then(saved => {
							return deleteFile(file);
						});
					} else {
						return deleteFile(file);
					}
				});
			});
		});
	});
Example #10
0
	@command('git.openFile')
	async openFile(arg?: Resource | Uri, ...resourceStates: SourceControlResourceState[]): Promise<void> {
		const preserveFocus = arg instanceof Resource;

		let uris: Uri[] | undefined;

		if (arg instanceof Uri) {
			if (arg.scheme === 'git') {
				uris = [Uri.file(fromGitUri(arg).path)];
			} else if (arg.scheme === 'file') {
				uris = [arg];
			}
		} else {
			let resource = arg;

			if (!(resource instanceof Resource)) {
				// can happen when called from a keybinding
				resource = this.getSCMResource();
			}

			if (resource) {
				uris = [...resourceStates.map(r => r.resourceUri), resource.resourceUri];
			}
		}

		if (!uris) {
			return;
		}

		const preview = uris.length === 1 ? true : false;
		const activeTextEditor = window.activeTextEditor;
		for (const uri of uris) {
			const opts: TextDocumentShowOptions = {
				preserveFocus,
				preview,
				viewColumn: ViewColumn.Active
			};

			// Check if active text editor has same path as other editor. we cannot compare via
			// URI.toString() here because the schemas can be different. Instead we just go by path.
			if (activeTextEditor && activeTextEditor.document.uri.path === uri.path) {
				opts.selection = activeTextEditor.selection;
			}

			const document = await workspace.openTextDocument(uri);
			await window.showTextDocument(document, opts);
		}
	}
Example #11
0
	test('Export DOT', async () => {
		let inputPath = path.join(fixturePath, 'ok.uif');
		let outputPath = path.join(fixturePath, 'ok.uif.dot');
		setResovleExportPath(() => {return Promise.resolve(outputPath); });
		let doc = await vscode.workspace.openTextDocument(inputPath);
		await vscode.window.showTextDocument(doc);
		await vscode.commands.executeCommand('uiflow.exportDOT');
		let buffer = fs.readFileSync(outputPath);
		let dot = String(buffer);
		if (!dot.match(/^digraph/)) {
			return Promise.reject(`DOT file doesn't start width 'digraph'.`);
		}
		if (!dot.match(/\}$/m)) {
			return Promise.reject(`DOT file doesn't end width '}'.`);
		}
	});
Example #12
0
	test('registerTextDocumentContentProvider, simple', function() {

		let registration = workspace.registerTextDocumentContentProvider('foo', {
			provideTextDocumentContent(uri) {
				return uri.toString();
			}
		});

		const uri = Uri.parse('foo://testing/virtual.js');
		return workspace.openTextDocument(uri).then(doc => {
			assert.equal(doc.getText(), uri.toString());
			assert.equal(doc.isDirty, false);
			assert.equal(doc.uri.toString(), uri.toString());
			registration.dispose();
		});
	});
Example #13
0
    return new Promise(function (resolve, reject) {

      workspace.openTextDocument(fileName).then((textDocument) => {
        if (!textDocument) {
          return reject('Could not open file!');
        }

        window.showTextDocument(textDocument).then((editor) => {
          if (!editor) {
            return reject('Could not show document!');
          }

          return resolve(editor);
        });
      });
    });
Example #14
0
    let openexport = vscode.commands.registerCommand('svgviewer.openexport', async function (uri) {
        if (!(uri instanceof vscode.Uri)) {
            if (vscode.window.activeTextEditor) {
                uri = vscode.window.activeTextEditor.document.uri;
            } else {
                return;
            }
        }
        let document = await vscode.workspace.openTextDocument(uri);
        if (checkNoSvg(document)) {
            vscode.window.showWarningMessage("Active editor doesn't show a SVG document - no properties to preview.");
            return;
        }

        return vscode.commands.executeCommand('vscode.previewHtml', makeExportUri(uri));
    });
Example #15
0
	test('Test provideRenameEdits#UiflowRenameProvider', async () => {
		const doc = await vscode.workspace.openTextDocument(path.join(fixturePath, 'rename.uif'));
		const position = new vscode.Position(4, 4);
		const newName = 'sec1';
		const provider = new UiflowRenameProvider();
		const we = await provider.provideRenameEdits(doc, position, newName, null);
		const expected: vscode.Range[] = [
			new vscode.Range(0, 1, 0, 8),
			new vscode.Range(4, 4, 4, 11),
			new vscode.Range(10, 4, 10, 11)
		];
		const edits = we.get(doc.uri);
		expected.forEach((range, i) => {
			assert.ok(range.isEqual(edits[i].range), `Range should be equal.`);
		});
	});
Example #16
0
 test('format().capitalize()', async () => {
     const textDocument = await vscode.workspace.openTextDocument(fileStringFormat);
     await vscode.window.showTextDocument(textDocument);
     const position = new vscode.Position(5, 41);
     const def = await vscode.commands.executeCommand<vscode.Hover[]>('vscode.executeHoverProvider', textDocument.uri, position);
     assert.equal(def.length, 1, 'Definition length is incorrect');
     assert.equal(def[0].contents.length, 1, 'Only expected one result');
     const contents = normalizeMarkedString(def[0].contents[0]);
     if (contents.indexOf("def capitalize") === -1) {
         assert.fail(contents, "", "'def capitalize' is missing", "compare");
     }
     if (contents.indexOf("Return a capitalized version of S") === -1 &&
         contents.indexOf("Return a copy of the string S with only its first character") === -1) {
         assert.fail(contents, "", "'Return a capitalized version of S/Return a copy of the string S with only its first character' message missing", "compare");
     }
 });
Example #17
0
					}).then(selected => {
						if (!selected || selected.index !== 0) {
							return;
						}
						if (!isImplicitProjectConfigFile(configFileName)) {
							vscode.workspace.openTextDocument(configFileName)
								.then(vscode.window.showTextDocument);
						} else {
							const root = client.getWorkspaceRootForResource(vscode.Uri.file(configFileName));
							if (root) {
								openOrCreateConfigFile(
									configFileName.match(/tsconfig\.?.*\.json/) !== null,
									root);
							}
						}
					});
Example #18
0
			changeEdit.edits.forEach((fileEdit) => {
				const uri = Uri.file(changeEdit.file);
				const promise = workspace.openTextDocument(uri);
				promises.push(
					promise.then((document) =>
						workspaceEdit.replace(
							uri,
							new Range(
								document.positionAt(fileEdit.offset),
								document.positionAt(fileEdit.offset + fileEdit.length),
							),
							fileEdit.replacement,
						),
					),
				);
			});
Example #19
0
        vscode.window.showQuickPick(options).then(label => {
            if (!label) { return; }

            const file: FileData = files.find(file => file.label === label);

            // If a command is being run then don't show the default list of files and folders
            if (commands.handle(label, cmdData)) { return; }

            if (file.isDirectory) {
                showFileList(file.path);
            } else if (file.isFile) {
                vscode.workspace.openTextDocument(file.path).then(doc => {
                    vscode.window.showTextDocument(doc);
                });
            }
        });
 protected confirmPath(): Thenable<any> {
     let uriToOpen = vscode.Uri.file(this.filePath);
     let confirmPromise = vscode.workspace.openTextDocument(uriToOpen)
         .then((textDocument) => {
             if(!languagesToCompileOnSave.has(textDocument.languageId)){
                 return Promise.reject(`Can not compile this file: ${this.filePath}`);
             } else if(this.filePath.includes('apex-scripts')){
                 return Promise.reject(`Local Apex Scripts can't be compiled. You can run them with Run Apex Script`);
             }else if(this.filePath.includes('resource-bundles')){
                 return Promise.reject(`Files inside Resource Bundles cannot be compiled. Use Deploy Resource Bundle instead`);
             } else {
                 return super.confirmPath();
             }
         });
     return confirmPromise;
 }
    context.subscriptions.push(vscode.commands.registerCommand('extension.showHtmlEscape', async () => {
        let previewDocument = await vscode.workspace.openTextDocument(previewUri);
        let previewEditorShowOptions: vscode.TextDocumentShowOptions = {
            viewColumn: vscode.ViewColumn.Beside, 
            preview: true,
            preserveFocus: true,
            selection: new vscode.Selection(new vscode.Position(0, 0), new vscode.Position(0, 0))
        };

        await vscode.window.showTextDocument(previewDocument, previewEditorShowOptions);

        let activeTextEditor = vscode.window.activeTextEditor;
        if (activeTextEditor && activeTextEditor.document.uri.scheme != htmlEsc.HtmlEscapeTextDocumentContentProvider.scheme) {
            provider.show(previewUri, activeTextEditor.document.uri, activeTextEditor.selections);
        }
    }));
Example #22
0
 test('For custom class', done => {
     let textEditor: vscode.TextEditor;
     let textDocument: vscode.TextDocument;
     vscode.workspace.openTextDocument(fileOne).then(document => {
         textDocument = document;
         return vscode.window.showTextDocument(textDocument);
     }).then(editor => {
         assert(vscode.window.activeTextEditor, 'No active editor');
         textEditor = editor;
         const position = new vscode.Position(30, 4);
         return vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
     }).then(list => {
         assert.notEqual(list.items.filter(item => item.label === 'method1').length, 0, 'method1 not found');
         assert.notEqual(list.items.filter(item => item.label === 'method2').length, 0, 'method2 not found');
     }).then(done, done);
 });
Example #23
0
const successNslAssembler = (choice): void => {
  let doc = window.activeTextEditor.document;

  if (choice === 'Open') {
    let dirName = dirname(doc.fileName);
    let extName = extname(doc.fileName);
    let baseName = basename(doc.fileName, extName);
    let outName = baseName + '.nsi';
    let nsisFile = join(dirName, outName);

    workspace.openTextDocument(nsisFile)
    .then( (doc) => {
      window.showTextDocument(doc);
    });
  }
};
 test('With Config', done => {
     let textEditor: vscode.TextEditor;
     let textDocument: vscode.TextDocument;
     return vscode.workspace.openTextDocument(fileToFormatWithConfig).then(document => {
         textDocument = document;
         return vscode.window.showTextDocument(textDocument);
     }).then(editor => {
         assert(vscode.window.activeTextEditor, 'No active editor');
         textEditor = editor;
         const sorter = new PythonImportSortProvider();
         return sorter.sortImports(extensionDir, textDocument);
     }).then(edits => {
         const newValue = `from third_party import lib2${EOL}from third_party import lib3${EOL}from third_party import lib4${EOL}from third_party import lib5${EOL}from third_party import lib6${EOL}from third_party import lib7${EOL}from third_party import lib8${EOL}from third_party import lib9${EOL}`;
         assert.equal(edits.filter(value => value.newText === newValue && value.range.isEqual(new vscode.Range(0, 0, 3, 0))).length, 1, 'New Text not found');
     }).then(done, done);
 });
 test('Without Config (via Command)', done => {
     let textEditor: vscode.TextEditor;
     let textDocument: vscode.TextDocument;
     let originalContent = '';
     return vscode.workspace.openTextDocument(fileToFormatWithoutConfig).then(document => {
         textDocument = document;
         originalContent = textDocument.getText();
         return vscode.window.showTextDocument(textDocument);
     }).then(editor => {
         assert(vscode.window.activeTextEditor, 'No active editor');
         textEditor = editor;
         return vscode.commands.executeCommand('python.sortImports');
     }).then(() => {
         assert.notEqual(originalContent, textDocument.getText(), 'Contents have not changed');
     }).then(done, done);
 });
Example #26
0
 test('With Unicode Characters', done => {
     let textEditor: vscode.TextEditor;
     let textDocument: vscode.TextDocument;
     vscode.workspace.openTextDocument(fileEncoding).then(document => {
         textDocument = document;
         return vscode.window.showTextDocument(textDocument);
     }).then(editor => {
         assert(vscode.window.activeTextEditor, 'No active editor');
         textEditor = editor;
         const position = new vscode.Position(25, 4);
         return vscode.commands.executeCommand<vscode.CompletionList>('vscode.executeCompletionItemProvider', textDocument.uri, position);
     }).then(list => {
         assert.equal(list.items.filter(item => item.label === 'bar').length, 1, 'bar not found');
         const documentation = `说明 - keep this line, it works${EOL}delete following line, it works${EOL}如果存在需要等待审批或正在执行的任务,将不刷新页面`;
         assert.equal(list.items.filter(item => item.label === 'bar')[0].documentation, documentation, 'unicode documentation is incorrect');
     }).then(done, done);
 });
Example #27
0
export function createTempDocument(content?: string) {

    const uri = Uri.parse(`untitled:${__dirname}.${Math.random()}.tmp`);

    return workspace.openTextDocument(uri)
        .then(document => {
            return window.showTextDocument(document);
        })
        .then(() => {
            if (content) {
                return window.activeTextEditor.edit(editBuilder => {
                    editBuilder.insert(new Position(0, 0), content);
                });
            }
        });

}
Example #28
0
	@command('git.openFile')
	async openFile(arg?: Resource | Uri, ...resourceStates: SourceControlResourceState[]): Promise<void> {
		const preserveFocus = arg instanceof Resource;

		let uris: Uri[] | undefined;

		if (arg instanceof Uri) {
			if (arg.scheme === 'git') {
				uris = [Uri.file(fromGitUri(arg).path)];
			} else if (arg.scheme === 'file') {
				uris = [arg];
			}
		} else {
			let resource = arg;

			if (!(resource instanceof Resource)) {
				// can happen when called from a keybinding
				resource = this.getSCMResource();
			}

			if (resource) {
				uris = [...resourceStates.map(r => r.resourceUri), resource.resourceUri];
			}
		}

		if (!uris) {
			return;
		}

		const preview = uris.length === 1 ? true : false;
		const activeTextEditor = window.activeTextEditor;
		for (const uri of uris) {
			const opts: TextDocumentShowOptions = {
				preserveFocus,
				preview: preview,
				viewColumn: activeTextEditor && activeTextEditor.viewColumn || ViewColumn.One
			};

			if (activeTextEditor && activeTextEditor.document.uri.fsPath === uri.fsPath) {
				opts.selection = activeTextEditor.selection;
			}

			const document = await workspace.openTextDocument(uri);
			await window.showTextDocument(document, opts);
		}
	}
Example #29
0
function onConfigureExcludesSelected(
	client: ITypeScriptServiceClient,
	configFileName: string
) {
	if (!isImplicitProjectConfigFile(configFileName)) {
		vscode.workspace.openTextDocument(configFileName)
			.then(vscode.window.showTextDocument);
	} else {
		const root = client.getWorkspaceRootForResource(vscode.Uri.file(configFileName));
		if (root) {
			openOrCreateConfigFile(
				configFileName.match(/tsconfig\.?.*\.json/) !== null,
				root,
				client.configuration);
		}
	}
}
 function testFormatting(formatter: AutoPep8Formatter | YapfFormatter, formattedContents: string, fileToFormat: string): PromiseLike<void> {
     let textEditor: vscode.TextEditor;
     let textDocument: vscode.TextDocument;
     return vscode.workspace.openTextDocument(fileToFormat).then(document => {
         textDocument = document;
         return vscode.window.showTextDocument(textDocument);
     }).then(editor => {
         textEditor = editor;
         return formatter.formatDocument(textDocument, null, null);
     }).then(edits => {
         return textEditor.edit(editBuilder => {
             edits.forEach(edit => editBuilder.replace(edit.range, edit.newText));
         });
     }).then(edited => {
         assert.equal(textEditor.document.getText(), formattedContents, 'Formatted text is not the same');
     });
 }