It is possible that the Levenshtein Distance may be of some help to you. It assesses similarity between two strings, then provides a score quantifying similarity. There is a great page describing the method on Wikipedia:
You can try the Trigram Algorithm, because it can find words or parts of strings that have a higher probability of being synonyms based on known information about the language and its vocabulary. The vocabulary with programming languages is not a problem, especially with reserved words and defined variable/constant/function names.
Also, Hamming distance can be used, because it compares two strings. It might be difficult to use it on strings that have not been "prepared" or processed, but it is worth looking into.
You could use a machine learning net or neural net that is trained in advanced to recognized similar words (supervised learning). Otherwise, hand-tuning suggested algorithmic approaches will be one obstacle (http://www.aclweb.org/anthology/P08-3001). See the same article for a supervised learning approach.
While source code contains natural language, it contains much more i.e., what will be the granularity of the retrieval (e.g., a line of code, a function, a file) and comments are extracted from each source code document, as they represent the ... contain some source code-specific terms, like programming keywords, which is of no use to text retrieval techniques.