How to use the vscode-languageserver.Position.create function in vscode-languageserver

To help you get started, we’ve selected a few vscode-languageserver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github iamcco / vim-language-server / src / handles / signatureHelp.ts View on Github external
(params: TextDocumentPositionParams): SignatureHelp | undefined => {
    const { textDocument, position } = params;
    const doc = documents.get(textDocument.uri);
    if (!doc) {
      return;
    }

    const currentLine = doc.getText(
      Range.create(
        Position.create(position.line, 0),
        Position.create(position.line + 1, 0),
      ),
    );

    // comment line
    if (commentPattern.test(currentLine)) {
      return;
    }

    const preSegment = currentLine.slice(0, position.character);

    const m = preSegment.match(/([\w#&:]+)[ \t]*\(([^()]*|\([^)]*\))*$/);
    if (!m) {
      return;
    }
    const functionName = m["1"];
github forcedotcom / lightning-language-server / packages / lwc-language-server / src / javascript / compiler.ts View on Github external
export function toVSCodeRange(babelRange: SourceLocation): Range {
    // babel (column:0-based line:1-based) => vscode (character:0-based line:0-based)
    return Range.create(Position.create(babelRange.start.line - 1, babelRange.start.column), Position.create(babelRange.end.line - 1, babelRange.end.column));
}
github coq-community / vscoq / server / src / util / text-util.ts View on Github external
export function positionAtRelative(start: Position, text: string, offset: number) : Position {
  if(offset > text.length)
    offset = text.length;
  let line = start.line;
  let currentOffset = 0;  // offset into text we are current at; <= `offset`
  let lineOffset = start.character;
  while(true) {
    const match = lineEndingRE.exec(text.substring(currentOffset));
    // match[0] -- characters plus newline
    // match[1] -- characters up to newline
    // match[2] -- newline (\n, \r, or \r\n)
    if(!match || match[0].length === 0 || currentOffset + match[1].length >= offset)
      return Position.create(line, lineOffset + Math.max(offset - currentOffset, 0))
    currentOffset+= match[0].length;
    lineOffset = 0;
    ++line;
  }
}
github apollographql / apollo-tooling / packages / apollo-language-server / src / utilities / source.ts View on Github external
export function positionInContainingDocument(
  source: Source,
  position: Position
): Position {
  if (!source.locationOffset) return position;
  return Position.create(
    source.locationOffset.line - 1 + position.line,
    position.character
  );
}
github Tencent / LuaPanda / src / code / server / docSymbolProcesser.ts View on Github external
let nodeLoc1 = Location.create(this.docInfo["docUri"], loc);
				let res1 = this.isInLocation(nodeLoc1, this.searchPosition);
				if (res1 === true){
					this.posSearchRet =  this.createRetSymbol(node["identifier"].name, node["identifier"].isLocal);
					return;
				}
			}
			if (type === travelMode.FIND_REFS) {
				if (functionSearchName == this.searchInfo.originalName){
					let loc = node["identifier"]["loc"];
					let nodeLoc1 = Location.create(this.docInfo["docUri"], loc);
					this.refsLink.push(nodeLoc1);
				}
			}
			if (type === travelMode.BUILD) {
				let loct = Location.create(this.docInfo["docUri"], Range.create(Position.create(loc["start"]["line"] - 1, loc["start"]["column"]), Position.create(loc["end"]["line"] - 1, loc["end"]["column"])));
				let pushObj = this.createSymbolInfo(functionSearchName, functionSearchName, functionSearchName, SymbolKind.Function, loct, node["identifier"]["isLocal"], prefix, deepLayer.concat(), paramArray);
				newChunk = new Tools.chunkClass(functionSearchName, node.loc);
				this.pushToChunkList(newChunk.chunkName, newChunk);
				pushObj.chunk = newChunk;
				this.pushToAutoList(pushObj);

			}
		//有名函数 成员函数的情况 function a.b()
		} else if (node["identifier"] && node["identifier"]['type'] == 'MemberExpression') {
			let baseInfo =  this.baseProcess(node["identifier"]);
			functionSearchName = baseInfo.name;
			functionName = 'function ' + functionSearchName + paramString;
			if (type === travelMode.GET_DEFINE && searchRes === true) {
				let bname = this.MemberExpressionFind(node["identifier"]);
				if (bname.isInStat && bname.isInStat > 0) {
					this.posSearchRet = this.createRetSymbol(bname.name, bname.isLocal);
github schneiderpat / aspnet-helper / aspnet-helper-server / src / features / model / declarationInfo.ts View on Github external
lines.forEach((line, i) => {
            let result: RegExpExecArray | null;
            while ( (result = propertyRegExp.exec(line)) ) {
                let item = new PropertyPosition();
                item.property = result[1];

                let start = Position.create(i, result.index);
                let end = Position.create(i, result.index + result[0].length);
                item.range = Range.create(start, end);
                items.push(item);
            }
        });
        return items;
github elm-tooling / elm-language-server / src / providers / codeLensProvider.ts View on Github external
private createReferenceCodeLens(placementNode: SyntaxNode, uri: string) {
    return CodeLens.create(
      Range.create(
        Position.create(
          placementNode.startPosition.row,
          placementNode.startPosition.column,
        ),
        Position.create(
          placementNode.endPosition.row,
          placementNode.endPosition.column,
        ),
      ),
      {
        codeLensType: "referenceCounter",
        uri,
      },
    );
  }
github iamcco / vim-language-server / src / server / workspaces.ts View on Github external
private getLocation(uri: string, item: IFunction | IIdentifier): Location {
    return {
      uri,
      range: Range.create(
        Position.create(item.startLine - 1, item.startCol - 1),
        Position.create(item.startLine - 1, item.startCol - 1 + item.name.length),
      ),
    };
  }
github coq-community / vscoq / server / src / util / text-util.ts View on Github external
export function positionAt(text: string, offset: number) : Position {
  if(offset > text.length)
    offset = text.length;
  let line = 0;
  let lastIndex = 0;
  while(true) {
    const match = lineEndingRE.exec(text.substring(lastIndex));
    if(lastIndex + match[1].length >= offset)
      return Position.create(line, Math.max(offset - lastIndex,0))
    lastIndex+= match[0].length;
    ++line;
  }
}
github microsoft / pyright / server / src / languageService / documentSymbolProvider.ts View on Github external
function convertPosition(position: DiagnosticTextPosition): Position {
    return Position.create(position.line, position.column);
}